Skip to content

Code node

The Code node runs a snippet of JavaScript inside a locked-down sandbox — the escape hatch for anything the built-in nodes don't cover. Reshape data, compute a value, parse a string, build a payload: whatever you can express in a few lines of JS, return it and the rest of the flow can read it.

Component id: flowrunner/code.

How it works

Your code runs as the body of a function that receives input — an object holding every flow variable so far (input.start, input.response, and any variable an earlier node wrote). Whatever you return becomes the node's output.

js
// input.start holds the request inputs
const items = input.start.items || [];
return { count: items.length, first: items[0] };

The return value is stored under your result variable:

  • an object return is stored as-is — read result.field;
  • a scalar (string / number / boolean / array) is wrapped as { value: ... } — read result.value;
  • returning nothing (or undefined) stores { value: null }.

The sandbox

The code runs in a QuickJS WebAssembly interpreter — a genuine isolation boundary, not eval. Inside it there is:

  • no network (fetch is undefined), no filesystem, no require/import, no process;
  • no access to your secrets — only the flow's data (input) is passed in;
  • a memory cap and a time limit (default 1000 ms, max 5000 ms) — an infinite loop is aborted, not left to hang.

console.log is available but its output isn't captured yet. Because there's no network or host access, the Code node is for pure data work — for HTTP calls use the HTTP node, for AI use the AI node.

Config

FieldRequiredDescription
codeYesThe JavaScript to run. Receives input; return a value.
timeoutMsNo (default 1000)Wall-clock limit in milliseconds, capped at 5000.
resultVarNo (default output)The variable the return value is written to.

Ports

The Code node has a next port and an error port. If the code throws or times out and you have wired the error port, the failure routes there; otherwise it surfaces as a top-level error.

Examples

Reshape a list into a summary object:

js
const orders = input.start.orders || [];
const total = orders.reduce((sum, o) => sum + o.amount, 0);
return { orderCount: orders.length, totalAmount: total };

Compute a scalar and branch on it:

text
Code  code: "return (input.start.score || 0) >= 50"  resultVar: passed
If    condition: passed.value == true

Parse and normalize a string:

js
const raw = input.start.email || "";
return raw.trim().toLowerCase();
// → refs.output.value = "a@b.com"

TIP

The Code node can't reach the network. Do the fetch in an HTTP node first, then feed input.response.body into a Code node to transform it.

See also

FlowRunner — the no-code platform for small businesses.