cloudconvert-node
This is a lightweight wrapper for the CloudConvert API.
Feel free to use, improve or modify this wrapper! If you have questions contact us or open an issue on GitHub.
Installation
As usual:
npm install --save cloudconvert
Quickstart
var fs = ;var cloudconvert = new 'your_api_key'; fs;
You can use the CloudConvert API Console to generate ready-to-use JS code snippets using this wrapper.
The manual way
cloudconvert.convert()
creates a Process, start it and waits until it completes. In some cases it might be necessary that you do this steps seperately, as the following example shows:
var fs = ;var cloudconvert = new 'your_api_key'; // create the process. see https://cloudconvert.com/apidoc#createcloudconvert;
Download of multiple output files
In some cases it might be possible that there are multiple output files (e.g. converting a multi-page PDF to JPG). You can download them all to one directory using the downloadAll()
method.
var fs = ;var cloudconvert = new 'your_api_key'; fs;
Events
The Process
object emits the following Events:
Event | Description |
---|---|
error |
The conversion failed. You should always listen for this event: If there is no listener, the error will be thrown and might crash your application. |
finished |
The conversion is finished (but not yet downloaded). This event will only be emitted, if you do wait() for the process. (convert() does this automatically for you). |
progress |
Emitted every second with the current progress of the conversion. This event will only be emitted, if you do wait() for the process. |
uploaded |
The input file was uploaded. |
started |
The process was started. |
downloaded |
The output file was downloaded. |
downloadedAll |
Emitted after completed downloadAll() . Every single file will emit a seperate downloaded event. |
Error handling
The following example shows how to catch the different error types which can occur at conversions:
var fs = ;var cloudconvert = new 'your_api_key'; fs;
How to run tests?
Tests are based on mocha:
git https://github.com/cloudconvert/cloudconvert-node.git
cd cloudconvert-node
npm install -d
npm test
How to run integration tests?
By default, mocha does not run integration tests against the real CloudConvert API. To run integration tests, use the API_KEY
enviroment variable and run the integration tests:
git https://github.com/cloudconvert/cloudconvert-node.git
cd cloudconvert-node
npm install -d
export API_KEY="your_api_key"
npm run integration