# Node.js SDK

[transloadit/node-sdk](https://github.com/transloadit/node-sdk)

We have a fully featured software development kit for Node.js, to make it easy to talk to the Transloadit REST API from your Node apps.

## Install

**Note:** This documentation covers Node SDK v4 (ESM, Node.js 20+). For legacy docs, see[v3](https://github.com/transloadit/node-sdk/tree/v3) or[v2](https://github.com/transloadit/node-sdk/tree/v2). For upgrade details, read the[v3 → v4 migration guide](https://github.com/transloadit/node-sdk/blob/main/MIGRATION.md).

Use `@transloadit/node` as the package name. The legacy `transloadit` npm package name is kept as an alias for backward compatibility.

Inside your project, type:

![](/_next/static/media/copy.04p1cju9qekk_.svg?dpl=dpl_CtwzFbHWtqiCy9uvWb9fE7WvfP9N)

```bash
yarn add @transloadit/node

```

or

![](/_next/static/media/copy.04p1cju9qekk_.svg?dpl=dpl_CtwzFbHWtqiCy9uvWb9fE7WvfP9N)

```bash
npm install --save @transloadit/node

```

## CLI

This package ships with a full-featured CLI:

![](/_next/static/media/copy.04p1cju9qekk_.svg?dpl=dpl_CtwzFbHWtqiCy9uvWb9fE7WvfP9N)

```bash
export TRANSLOADIT_KEY="YOUR_TRANSLOADIT_KEY"
export TRANSLOADIT_SECRET="YOUR_TRANSLOADIT_SECRET"
npx -y @transloadit/node --help

```

###### Note

The CLI binary is still called `transloadit`, so command examples may use`npx transloadit ...`.

## CommonJS projects

The SDK is ESM-only. If you are on CommonJS, use a dynamic import:

![](/_next/static/media/copy.04p1cju9qekk_.svg?dpl=dpl_CtwzFbHWtqiCy9uvWb9fE7WvfP9N)

```javascript
async function getClient() {
  const { Transloadit } = await import('@transloadit/node')
  return new Transloadit({
    authKey: process.env.TRANSLOADIT_KEY,
    authSecret: process.env.TRANSLOADIT_SECRET,
  })
}

```

## Usage

The following code will upload an image and resize it to a thumbnail:

![](/_next/static/media/copy.04p1cju9qekk_.svg?dpl=dpl_CtwzFbHWtqiCy9uvWb9fE7WvfP9N)

```javascript
import { ApiError, Transloadit } from '@transloadit/node'

const transloadit = new Transloadit({
  authKey: 'YOUR_TRANSLOADIT_KEY',
  authSecret: 'YOUR_TRANSLOADIT_SECRET',
})

try {
  const options = {
    files: {
      file1: '/PATH/TO/FILE.jpg',
    },
    params: {
      steps: {
        // You can have many Steps. In this case we will just resize any inputs (:original)
        resize: {
          use: ':original',
          robot: '/image/resize',
          result: true,
          width: 75,
          height: 75,
        },
      },
      // OR if you already created a template, you can use it instead of "steps":
      // template_id: 'YOUR_TEMPLATE_ID',
    },
    waitForCompletion: true, // Wait for the Assembly (job) to finish executing before returning
  }

  const status = await transloadit.createAssembly(options)

  if (status.results.resize) {
    console.log('✅ Success - Your resized image:', status.results.resize[0].ssl_url)
  } else {
    console.log("❌ The Assembly didn't produce any output. Make sure you used a valid image file")
  }
} catch (err) {
  console.error('❌ Unable to process Assembly.', err)
  if (err instanceof ApiError && err.assemblyId) {
    console.error(`💡 More info: https://transloadit.com/assemblies/${err.assemblyId}`)
  }
}

```

You can find [details about your executed Assemblies here](/assemblies/).

## Examples

* [Upload and resize image](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/resize%5Fan%5Fimage.ts)
* [Upload image and convert to WebP](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/convert%5Fto%5Fwebp.ts)
* [Rasterize SVG to PNG](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/rasterize%5Fsvg%5Fto%5Fpng.ts)
* [Crop a face out of an image and download the result](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/face%5Fdetect%5Fdownload.ts)
* [Retry example](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/retry.ts)
* [Calculate total costs (GB usage)](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/fetch%5Fcosts%5Fof%5Fall%5Fassemblies%5Fin%5Ftimeframe.ts)
* [Templates CRUD](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/template%5Fapi.ts)
* [Template credentials CRUD](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/credentials.ts)

For more fully working examples take a look at[examples/](https://github.com/transloadit/node-sdk/blob/main/packages/node/examples/).

## Documentation

See [GitHub](https://github.com/transloadit/node-sdk#readme) for the full documentation and the[migration guide](https://github.com/transloadit/node-sdk/blob/main/MIGRATION.md) for v3 → v4 upgrade details.
