Code Node (& Function Node)

The Code Node runs synchronous JavaScript in a QuickJS sandbox. No async, no network, no modules.

Written By pvdyck

Last updated 22 minutes ago

Code Node (& Function Node)

The Code Node lets you run custom JavaScript logic inside your workflow. On indie.money, it runs inside a QuickJS sandbox -- a lightweight JavaScript engine with significant constraints.

Modes

ModeDescription
Run Once for All ItemsYour code receives all input items as an array. Return an array of items.
Run Once for Each ItemYour code runs once per item. Return a single item each time.

Available Built-ins

CategoryAvailable
JavaScriptMath, Date, JSON, Array, Object, String, RegExp, Number, parseInt, parseFloat, isNaN, isFinite, encodeURI, decodeURI
n8n Data$input, $json, $binary, $node, $workflow, $env, $vars, $execution, $now, $today, $yesterday, DateTime (Luxon)
Cross-node$('NodeName'), $node['Name'], $item(n), $items(), $prevNode
Context$mode, $nodeVersion, $nodeId, $itemIndex, $runIndex, $getNodeParameter

Key Limitations

  • No async/await -- All code must be synchronous
  • No fetch / HTTP -- Cannot make network requests (use HTTP Request Node instead)
  • No require / import -- No external modules available
  • No console.log -- Use return to output data; logs are discarded
  • 2-minute CPU limit -- Execution stops after 2 minutes of CPU time
  • No file system access -- Cannot read or write files
  • JavaScript only -- Python mode (available in standard n8n) is not supported

Example (Run Once for All Items)

const items = $input.all();return items.map(item => ({  json: {    ...item.json,    price_usd: (item.json.price_cents / 100).toFixed(2)  }}));

Example (Run Once for Each Item)

return {  json: {    fullName: $json.firstName + ' ' + $json.lastName,    processed: true  }};

Debugging Tips

  • Return intermediate values to inspect them in the output panel
  • Use JSON.stringify() to inspect nested objects
  • Test logic locally in a browser console first (no async constraints there)

Related