Search Docs
Loading...
Skip to content

Node.js - New Project

This guide walks you through integrating the CreativeEditor SDK (CE.SDK) Engine in a Node.js environment using Vanilla JavaScript (CommonJS or ES modules), enabling you to process images and designs programmatically. By the end of this guide, you’ll have a working Node.js script that loads a scene, modifies it, and exports it as an image.

What’s CreativeEditor SDK?#

CreativeEditor SDK (CE.SDK) lets you integrate a customizable image and video editor into your web app. It includes filters, text overlays, and other media editing tools, and adapts easily to your use case.

CreativeEditor SDK is a commercial product. To use it, you need a valid license key. If you don’t have one yet, contact our sales team or purchase a license.

Contact Sales

Purchase License

Who Is This Guide For?#

This guide is for developers who:

  • Need to perform image editing and scene manipulation programmatically in a Node.js environment using plain JavaScript.
  • Want to use CE.SDK’s Node.js package for automation or backend processing without TypeScript or additional frameworks.
  • Prefer a script-based approach for design generation and image exports.

What You’ll Achieve#

  • Install and configure CE.SDK Engine for Node.js.
  • Load and manipulate design scenes programmatically using plain JavaScript.
  • Export designs as PNG images without requiring a UI.

Engines#

@cesdk/node runs the native engine. Where the native engine cannot run, it starts the WASM engine, with the same API. The engine option of CreativeEngine.init() chooses the engine:

engine Starts
'auto' (default) The native engine. The WASM engine when the host has no native binary, the binary does not load or the license does not cover the native engine.
'native' The native engine, or an error when it cannot start.
'wasm' The WASM engine.

When 'auto' starts the WASM engine, it logs the reason once per process, through your logger or on stderr, in a line that starts with [CreativeEngine] Using the WASM engine:. The level is Warning when the native engine is installed on a host that it supports but does not load or start, or cannot reach the license server for an API key, and Info otherwise. The native engine reads its own resources, such as fonts and ICU data, from the @cesdk/node package, so baseURL can point at your own assets, on the local disk or remote. Without the engine option, the CESDK_ENGINE environment variable chooses the engine, so a deployment can change it without a code change. An instance keeps its engine until you dispose it.

The native engine runs on macOS (ARM/x64), Linux (x64 or ARM64, glibc 2.39 or later) and Windows (x64). Other hosts, such as Alpine Linux (musl), AWS Lambda or Windows ARM64, run the WASM engine.

The native engine exports MP4 and WebM video. It renders on the GPU (Metal on macOS, EGL on Linux, Direct3D 12 on Windows) with a CPU fallback. Unlike the WASM engine, it has no 4 GB memory limit. The WASM engine has no video export on Node.js and renders on the CPU. On the WASM engine, attachCanvas, getFrameInfo and editor.supportsP3 throw an error with the code ERR_CESDK_NATIVE_ENGINE_REQUIRED, and block.exportVideo and block.exportVideoToBuffer return a promise that rejects with it.

If your pipeline needs video export, pass engine: 'native'. CreativeEngine.init() then throws an error instead of starting the WASM engine:

const engine = await CreativeEngine.init({
license: 'YOUR_CESDK_LICENSE_KEY',
engine: 'native',
});

Prerequisites#

Before getting started, ensure you have:

  • Node.js v22 or later installed. (Download Node.js).
  • A valid CE.SDK license key - Required for engine initialization. Contact sales to get your license key.

Step 1: Set Up Your Project#

Create a new project folder and navigate into it:

Terminal window
mkdir my-cesdk-node-project
cd my-cesdk-node-project

Next, create a new index.js file manually or by running:

Terminal window
touch index.js

Step 2: Install CE.SDK for Node.js#

Run the following command to install the required packages:

Terminal window
npm install @cesdk/node@1.87.0-rc.3

Your project structure should now look like this:

/my-cesdk-node-project
├── node_modules
├── index.js
└── package.json

For your index.js, you can either use ES modules or CommonJS. Both versions are shown below.

index.js (ES Modules)#

If your project is using ES modules, change the package.json file to include:

{
"type": "module"
}

Then, modify index.js to use ES modules (import syntax):

import fs from 'fs/promises';
import CreativeEngine from '@cesdk/node';
// Configuration for the engine
const config = {
// license: 'YOUR_CESDK_LICENSE_KEY', // Replace with your CE.SDK license key
};
try {
// Initialize CE.SDK Engine
const engine = await CreativeEngine.init(config);
console.log('CE.SDK Engine initialized');
try {
// Load a scene from a URL
await engine.scene.load(
'https://cdn.img.ly/assets/demo/v3/ly.img.template/templates/cesdk_instagram_photo_1.scene',
);
// Find the first page in the scene
const [page] = engine.block.findByType('page');
// Export the scene as a PNG image
const blob = await engine.block.export(page, { mimeType: 'image/png' });
const arrayBuffer = await blob.arrayBuffer();
// Save the exported image to the file system
await fs.writeFile('./example-output.png', Buffer.from(arrayBuffer));
console.log('Export completed: example-output.png');
} catch (error) {
console.error('Error processing scene:', error);
} finally {
// Dispose of the engine to free resources
engine.dispose();
}
} catch (initError) {
console.error('Failed to initialize CE.SDK Engine:', initError.message);
process.exit(1);
}

index.js (CommonJS)#

Modify your index.js file to initialize CE.SDK Engine and process a scene using CommonJS (require syntax):

const fs = require('fs/promises');
const CreativeEngine = require('@cesdk/node');
const { MimeType } = CreativeEngine;
// Configuration for the engine
const config = {
// license: 'YOUR_CESDK_LICENSE_KEY', // Replace with your CE.SDK license key
};
// Initialize CE.SDK Engine
CreativeEngine.init(config)
.then(async engine => {
console.log('CE.SDK Engine initialized');
try {
// Load a scene from a URL
await engine.scene.load(
'https://cdn.img.ly/assets/demo/v3/ly.img.template/templates/cesdk_instagram_photo_1.scene',
);
// Find the first page in the scene
const [page] = engine.block.findByType('page');
// Export the scene as a PNG image
const blob = await engine.block.export(page, { mimeType: 'image/png' });
const arrayBuffer = await blob.arrayBuffer();
// Save the exported image to the file system
await fs.writeFile('./example-output.png', Buffer.from(arrayBuffer));
console.log('Export completed: example-output.png');
} catch (error) {
console.error('Error processing scene:', error);
} finally {
// Dispose of the engine to free resources
engine.dispose();
}
})
.catch(initError => {
console.error('Failed to initialize CE.SDK Engine:', initError.message);
process.exit(1);
});

Step 3: Run the Script#

Once everything is set up, run your script using:

Terminal window
node index.js

This code processes the scene and generates an image file named example-output.png in your project directory.

Troubleshooting & Common Errors#

❌ Error: fetch is not defined

  • If using Node.js v16 or lower, this error can occur. We only support Node.js v22 and above.

❌ Error: Invalid license key

  • Verify that your license key is correct and not expired.

❌ Error: SyntaxError: Cannot use import statement outside a module

  • If using ES modules, ensure "type": "module" is set in package.json.
  • If using CommonJS, ensure require() is used instead of import.

Development Best Practices#

  • Always handle initialization errors - CE.SDK initialization can fail for various reasons. Common reasons are:

  • Invalid license

  • Network issues

  • Dispose resources - Always call engine.dispose() in a finally block to free memory.

  • Use async/await - The async/await pattern is generally cleaner than promise chains for CE.SDK operations.

Next Steps#

Congratulations! You’ve successfully integrated CE.SDK Engine in Node.js using plain JavaScript. Next, explore: