Skip to main content

What It Does

The JavaScript Code node executes a JS snippet in an isolated environment with no access to the network or file system. Use it when data transformations become too complex for {{ }} expressions, or when you need conditional logic, iteration, or string manipulation that other nodes do not cover natively. Typical use cases:
  • Transform the structure of a JSON returned by an external API
  • Validate fields and throw descriptive errors when data is missing
  • Calculate derived values (discount, due date, hash)
  • Combine data from multiple upstream nodes into a single object
  • Format strings: masked IDs, localized dates, URL slugs

Input and Output

Variables available in the code scope: Output: the value returned via return is exposed as $json to downstream nodes. It can be an object, array, string, number, or boolean.

Configuration

1

Add the node to the flow

In the component palette, select Actions > JavaScript Code and drag it onto the canvas.
2

Write the code in the editor

The editor accepts modern JavaScript (ES2020+). Use return to define the node’s output.Auto-generated starter template:
3

Reference flow variables

Do not use {{ }} expressions inside JS code — access data through the global variables:
4

Use console.log for debugging

console.log() is available and logs appear in the node’s execution panel during tests. In production, logs are discarded.
5

Test the node

Click Test in the node panel. The runtime executes the code with the pinned output data from upstream nodes and displays the result and execution duration.

Available APIs

The runtime is isolated — there is no access to the network, file system, or environment variables. The available JavaScript APIs are:

Examples

Transform API response structure

The external API returns a format different from what downstream nodes expect.

Format and validate a CPF

The downstream Condition node checks {{ $json.valido }} and routes to the error path when false.

Calculate a due date


Combine data from multiple nodes

When you need to assemble an object with fields coming from different nodes (HTTP, LLM, and trigger), use the JavaScript node as a consolidation point before sending.

Filter and sort an array


Error Handling

If the code throws an uncaught exception, the node marks the execution as failed and the error appears in the execution logs. To handle errors in a controlled way, use try/catch:

Limits

Infinite loops or very heavy synchronous operations cause a timeout after 10 seconds. Prefer array processing with Array.map() and Array.filter() instead of while loops without a clear exit condition.

Next Steps