Workflow JavaScript code node
The module exports runCodeStep(action, input, { signal }). Adoption into the workflow engine is proposed separately; this module does not register an action in production.
Use language: 'javascript' and a JavaScript function body, for example:
console.log('Counting items');
return { total: $input.steps.s1.output.items.length };
$input is a deeply frozen JSON copy of the run context: { trigger: { record, event }, steps: { s1: { output } }, run: { id, workflowId } }. Async bodies and guest promises work. There is no filesystem, network, module loader, process, require, fetch or timer API. Date is the guest engine's built-in Date, with no host override.
The source must contain 1–20000 characters. timeoutMs is an integer from 50 to 2000 (default 1000); memoryMb is an integer from 8 to 64 (default 32). Two jobs can execute at once per API process. Each job uses a disposable worker and fresh QuickJS runtime. The runtime has memory, stack and execution interrupt limits; the parent terminates its worker at the timeout plus 250 ms even if the guest fails to cooperate. Queue wait is separate from execution time. Cancellation releases the job without running external effects.
Return a plain JSON object of at most 256 KiB encoded as UTF-8. Arrays at the root, cycles, functions, nonfinite numbers and values that JSON would silently drop are rejected. Captured console logs contain at most 50 lines and 4 KiB including separators. Success returns { ok: true, output, logs }; failure returns { ok: false, error: { code, message, line? } }. Error codes are timeout, memory, runtime and output_invalid. Messages are at most 500 characters; host stack frames are never returned.
The adoption proposal executes code in both normal and dry runs. Normal steps record applied, dry runs record planned, both retaining output and logs. Errors abort the segment using the existing rollback path. Logs and output can contain run data and must follow the adopter's tenant access and retention policy.
References: QuickJS API, n8n Code node. QuickJS 0.32.0 is MIT licensed.