> ## Documentation Index
> Fetch the complete documentation index at: https://autorender.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js / TypeScript

> Upload files, manage folders, and call the full Autorender API from your Node.js or TypeScript server.

The `@autorender/nodejs` SDK is the official server-side client for Node.js and TypeScript. Use it to upload files, list and manage files and folders, run multipart uploads, and call the Autorender API from your backend.

## Prerequisites

* An Autorender account with an API key — [create one in the dashboard](https://app.autorender.io)
* Node.js **18** or later

## Guide

<Steps>
  <Step title="Install the package.">
    <CodeGroup>
      ```bash npm theme={null}
      npm install @autorender/nodejs
      ```

      ```bash yarn theme={null}
      yarn add @autorender/nodejs
      ```

      ```bash pnpm theme={null}
      pnpm add @autorender/nodejs
      ```

      ```bash bun theme={null}
      bun add @autorender/nodejs
      ```
    </CodeGroup>
  </Step>

  <Step title="Set your API key.">
    Create an API key in the dashboard and set it as an environment variable:

    ```bash theme={null}
    export AUTORENDER_API_KEY=your-api-key
    ```
  </Step>

  <Step title="Upload a file.">
    Create a client and upload your first file. The client reads `AUTORENDER_API_KEY` from the environment — never hardcode the key.

    ```typescript {6} theme={null}
    import Autorender from '@autorender/nodejs';
    import fs from 'fs';

    const client = new Autorender({
      apiKey: process.env.AUTORENDER_API_KEY,
    });

    const upload = await client.uploads.create({
      file: fs.createReadStream('products/chair.jpg'),
      file_name: 'chair.jpg',
    });

    console.log(upload.file_no); // e.g. "fi_abc123"
    console.log(upload.url);     // CDN URL
    ```
  </Step>
</Steps>

## Examples

### Upload from URL

```typescript theme={null}
const upload = await client.uploads.createFromURL({
  remote_url: 'https://acme-assets.s3.amazonaws.com/products/chair.jpg',
});
```

### List files

```typescript theme={null}
const result = await client.files.list({ limit: 10 });

for (const file of result.files) {
  console.log(file.file_no, file.name, file.url);
}
```

### Get file details

```typescript theme={null}
const file = await client.files.retrieve('fi_abc123');
console.log(file.data.url);
```

### Rename a file

```typescript theme={null}
await client.files.rename('fi_abc123', { name: 'new-name' });
```

### Delete a file

```typescript theme={null}
await client.files.delete('fi_abc123');
```

### Folders

```typescript theme={null}
// List folders
const { folders } = await client.folders.list();

// Create a folder
const folder = await client.folders.create({ name: 'products' });

// Rename a folder
await client.folders.rename(folder.data.folder_no, { name: 'product-images' });

// Delete a folder
await client.folders.delete(folder.data.folder_no);
```

### Multipart upload

For files larger than **100 MB**, use a multipart upload to split the file into parts:

```typescript theme={null}
import fs from 'fs';

const fileBuffer = fs.readFileSync('large-video.mp4');

// Start session
const session = await client.multipartUploads.start({
  file_name: 'large-video.mp4',
  file_size: fileBuffer.length,
});

// Upload parts
const partRes = await fetch(session.parts[0].url, {
  method: 'PUT',
  body: fileBuffer,
});
const etag = partRes.headers.get('etag')!;

// Complete
const result = await client.multipartUploads.complete({
  upload_id: session.upload_id,
  parts: [{ part_number: 1, etag }],
});
```

### Error handling

```typescript theme={null}
import Autorender from '@autorender/nodejs';

try {
  const file = await client.files.retrieve('fi_notexist');
} catch (err) {
  if (err instanceof Autorender.APIError) {
    console.log(err.status);  // 404
    console.log(err.message);
  }
}
```

## Resources

* [npm package](https://www.npmjs.com/package/@autorender/nodejs)
* [GitHub](https://github.com/autorender/autorender-nodejs)
* [API reference](https://github.com/autorender/autorender-nodejs/blob/main/api.md)

## Next steps

<CardGroup cols={2}>
  <Card title="Direct upload API" icon="cloud-arrow-up" iconType="solid" href="/docs/api-reference/direct-upload">
    The upload endpoint this SDK calls.
  </Card>

  <Card title="Create an API key" icon="key" iconType="solid" href="/docs/create-an-api-key">
    Generate the key the client reads from the environment.
  </Card>

  <Card title="Image transformations" icon="wand-magic-sparkles" iconType="solid" href="/docs/transformations/introduction">
    Build delivery URLs from your uploaded files.
  </Card>

  <Card title="All SDKs" icon="cubes" iconType="solid" href="/docs/resources/sdks">
    Server-side clients for every language.
  </Card>
</CardGroup>
