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:| Variable | Type | Description |
|---|---|---|
input | any | Output of the immediately preceding node ($json) |
trigger | object | Full trigger payload (body, headers, query, method) |
vars | object | Workflow variables defined by Set Variable nodes |
return is exposed as $json to downstream nodes. It can be an object, array, string, number, or boolean.
Configuration
Add the node to the flow
In the component palette, select Actions > JavaScript Code and drag it onto the canvas.
Write the code in the editor
The editor accepts modern JavaScript (ES2020+). Use
return to define the node’s output.Auto-generated starter template:Reference flow variables
Do not use
{{ }} expressions inside JS code — access data through the global variables: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.Available APIs
The runtime is isolated — there is no access to the network, file system, or environment variables. The available JavaScript APIs are:| API | Available |
|---|---|
JSON.parse() / JSON.stringify() | yes |
Math.* | yes |
Date | yes |
RegExp | yes |
Array.* / Object.* / String.* | yes |
console.log() | yes (debug only) |
fetch() / XMLHttpRequest | no |
fs / path / Node.js modules | no |
setTimeout / setInterval | no |
require() / import | no |
Examples
Transform API response structure
The external API returns a format different from what downstream nodes expect.Format and validate a CPF
{{ $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, usetry/catch:
Limits
| Parameter | Value |
|---|---|
| Execution timeout | 10 seconds |
| Network access | Not allowed |
| File system access | Not allowed |
require() / external modules | Not supported |
| Maximum script size | No documented limit |
| Maximum output size | 10 MB |
Next Steps
- Variables Node — store the code output for use in multiple nodes
- LLM Node — use AI before JavaScript to extract unstructured data
- HTTP Request Node — send the object built by JavaScript to an external API
- Nodes overview — see all available node types