百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cloudconvert-node

> 编程语言
开源

CloudConvert Node.js SDK

190 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

CloudConvert Node.js SDK

cloudconvert-node

This is the official Node.js SDK for the CloudConvert API v2.

Installation

bash
npm install --save cloudconvert

Load as ESM module:

javascript
import CloudConvert from 'cloudconvert';

... or via require:

javascript
const CloudConvert = require('cloudconvert');

Creating Jobs

javascript
import CloudConvert from 'cloudconvert';

const cloudConvert = new CloudConvert('api_key');

let job = await cloudConvert.jobs.create({
    tasks: {
        'import-my-file': {
            operation: 'import/url',
            url: 'https://my-url'
        },
        'convert-my-file': {
            operation: 'convert',
            input: 'import-my-file',
            output_format: 'pdf',
            some_other_option: 'value'
        },
        'export-my-file': {
            operation: 'export/url',
            input: 'convert-my-file'
        }
    }
});

You can use the CloudConvert Job Builder to see the available options for the various task types.

Downloading Files

CloudConvert can generate public URLs for using export/url tasks. You can use these URLs to download output files.

javascript
job = await cloudConvert.jobs.wait(job.id); // Wait for job completion

const file = this.cloudConvert.jobs.getExportUrls(job)[0];

const writeStream = fs.createWriteStream('./out/' + file.filename);

https.get(file.url, function (response) {
    response.pipe(writeStream);
});

await new Promise((resolve, reject) => {
    writeStream.on('finish', resolve);
    writeStream.on('error', reject);
});

Uploading Files

Uploads to CloudConvert are done via import/upload tasks (see the docs). This SDK offers a convenient upload method:

javascript
const job = await cloudConvert.jobs.create({
    tasks: {
        'upload-my-file': {
            operation: 'import/upload'
        }
        // ...
    }
});

const uploadTask = job.tasks.find(task => task.name === 'upload-my-file');

const inputFile = fs.createReadStream('./file.pdf');

await cloudConvert.tasks.upload(uploadTask, inputFile, 'file.pdf');

Note on custom streams: The length of the stream needs to be known prior to uploading. The SDK tries to automatically detect the file size of file-based read streams. If you are using a custom stream, you might need to pass a fileSize as fourth parameter to the upload() method.

Websocket Events

The node SDK can subscribe to events of the CloudConvert socket.io API.

javascript
const job = await cloudConvert.jobs.create({ ... });

// Events for the job
// Available events: created, updated, finished, failed
cloudConvert.jobs.subscribeEvent(job.id, 'finished', event => {
    // Job has finished
    console.log(event.job);
});

// Events for all tasks of the job
// Available events: created, updated, finished, failed
cloudConvert.jobs.subscribeTaskEvent(job.id, 'finished', event => {
    // Task has finished
    console.log(event.task);
});

When you don't want to receive any events any more you should close the socket:

javascript
cloudConvert.closeSocket();

Webhook Signing

The node SDK allows to verify webhook requests received from CloudConvert.

javascript
const payloadString = '...'; // The JSON string from the raw request body.
const signature = '...'; // The value of the "CloudConvert-Signature" header.
const signingSecret = '...'; // You can find it in your webhook settings.

const isValid = cloudConvert.webhooks.verify(
    payloadString,
    signature,
    signingSecret
); // returns true or false

Signed URLs

Signed URLs allow converting files on demand only using URL query parameters. The node.js SDK allows to generate such URLs. Therefore, you need to obtain a signed URL base and a signing secret on the CloudConvert Dashboard.

…

Using the Sandbox

You can use the Sandbox to avoid consuming your quota while testing your application. The node SDK allows you to do that.

javascript
// Pass `true` to the constructor
const cloudConvert = new CloudConvert('api_key', true);

Don't forget to generate MD5 Hashes for the files you will use for testing.

Setting a Region

By default, the region in your account settings is used. Alternatively, you can set a fixed region:

javascript
// Pass the region as third argument to the constructor
const cloudConvert = new CloudConvert('api_key', false, 'us-east');

Contributing

This section is intended for people who want to contribute to the development of this library.

Getting started

Begin with installing the necessary dependencies by running

bash
npm install

in the root directory of this repository.

Building

This project is written in TypeScript so it needs to be compiled first:

bash
npm run build

This will compile the code in the lib directory and generate a built directory containing the JS files and the type declarations.

Unit Tests

Tests are based on mocha:

bash
npm run test

Integration Tests

bash
npm run test-integration

By default, this runs the integration tests against the Sandbox API with an official CloudConvert account. If you would like to use your own account, you can set your API key using the CLOUDCONVERT_API_KEY enviroment variable. In this case you need to whitelist the following MD5 hashes for Sandbox API (using the CloudConvert dashboard).

53d6fe6b688c31c565907c81de625046  input.pdf
99d4c165f77af02015aa647770286cf9  input.png

Linting

The project is linted by ESLint+Prettier.

If you're using VSCode, all files will be linted automatically upon saving. Otherwise, you can lint the project by running

bash
npm run lint

and even auto-fix as many things as possible by running

bash
npm run lint -- --fix

Resources

  • API v2 Documentation
  • CloudConvert Blog

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言