Skip to main content

Set up JavaScript for CDB EdgeCompute

The CDB EdgeCompute JavaScript SDK (@gcoredev/edgecompute-sdk-js) compiles JavaScript applications to WebAssembly so they can run on CDB's edge network. It is the recommended way to build CDB EdgeCompute applications in JavaScript.

Node.js v22 or higher is required.

Install the SDK

The steps below set up a minimal project manually. To scaffold a project from a template instead, run npm create edgecompute-app — it handles folder creation, dependency installation, and project structure interactively.

mkdir my-app
cd my-app
npm init -y
npm install --save-dev @gcoredev/edgecompute-sdk-js

npm init -y creates package.json with "type": "commonjs" by default. The SDK bundler requires ESM — change it before building:

npm pkg set type=module

After installation, three CLI tools are available via npx:

ToolPurpose
edgecompute-buildCompiles JavaScript to a WebAssembly binary
edgecompute-initCreates build config for repeatable builds
edgecompute-assetsPackages static files for edge serving

Write a handler

CDB EdgeCompute applications register a fetch event listener that receives an HTTP request and returns a response. Create src/index.js:

addEventListener('fetch', (event) => {
  event.respondWith(new Response('Hello from CDB EdgeCompute'));
});

The fetch event model follows the Service Worker API convention. event.respondWith() accepts a Response object or a Promise<Response>. Under the hood, the SDK compiles to the WASI P2 wasi:http/proxy world — the same standard used by the Modern Rust SDK.

Verify the toolchain

Compile the handler to a WebAssembly binary:

npx edgecompute-build --input src/index.js --output wasm/app.wasm

A successful build prints:

Build success!!
"src/index.js" -> "wasm/app.wasm"

The compiled binary is at ./wasm/app.wasm. That file can be uploaded to CDB EdgeCompute directly or used as the starting point for the next tutorial.