Work with data

Code node

Write JavaScript when the built-in nodes are not enough.

The Code node runs JavaScript when the other nodes aren't enough.

Modes

  • Run once for all items: your code runs once. $input.all() (or items) is every item; return an array.
  • Run once for each item: your code runs per item. $json is the current item; return one object.

Returning data

Return an array of items. Plain objects are fine; they're wrapped as { json: … } for you.

// Run once for all items
return $input.all().map(({ json }) => ({
  name: json.name.trim(),
  amountTzs: Math.round(json.amount),
}));
// Run once for each item
return { ...$json, vip: $json.amount > 100000 };

What's available

$input.all(), $input.first(), items, $json, $workflow, $vars (your variables), $now, and console.log (shown in the node's output).

Limits

The code runs in a sandbox: there's no network or file access and no require, and each run has a memory limit and a time limit. To call an API, use an HTTP Request node before or after the Code node.

Previous: Data tables · Next: Variables