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.

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.

Prerequisites

Before getting started, ensure you have:

Step 1: Install CE.SDK for Node.js

Run the following command to install the required packages:

Terminal window
# Install the CE.SDK Node.js package
npm install @cesdk/node

Step 2: Set Up Your Project Structure

Create the following file:

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

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';
const { MimeType } = CreativeEngine;
const config = {
license: 'YOUR_LICENSE_KEY',
baseURL: 'https://cdn.img.ly/packages/imgly/cesdk-node/1.51.0/assets',
};
CreativeEngine.init(config).then(async engine => {
console.log('CE.SDK Engine initialized');
try {
await engine.addDefaultAssetSources();
await engine.scene.loadFromURL(
'https://cdn.img.ly/assets/demo/v1/ly.img.template/templates/cesdk_instagram_photo_1.scene',
);
const [page] = engine.block.findByType('page');
const blob = await engine.block.export(page, MimeType.Png);
const arrayBuffer = await blob.arrayBuffer();
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 {
engine.dispose();
}
});

index.js (CommonJS)

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

const fs = require('fs/promises');
const CreativeEngine = require('@cesdk/node');
const { MimeType } = CreativeEngine;
// Configuration for the engine
const config = {
license: 'YOUR_LICENSE_KEY', // Replace with a valid license key
baseURL: 'https://cdn.img.ly/packages/imgly/cesdk-node/1.51.0/assets',
};
// Initialize CE.SDK Engine
CreativeEngine.init(config).then(async engine => {
console.log('CE.SDK Engine initialized');
try {
// Load default assets
await engine.addDefaultAssetSources();
// Load a scene from a URL
await engine.scene.loadFromURL(
'https://cdn.img.ly/assets/demo/v1/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.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();
}
});

Step 3: Run the Script

Once everything is set up, run your script using:

Terminal window
node index.js

This will process the scene and generate 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 v20 and above, as those are the officially maintained versions.

❌ 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.

Next Steps

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

  • Running on AWS Lambda
  • Automating Creative Workflows