- Configuration — the JavaScript editor, formatter, cheat sheet, autocomplete, and the DLP section.
- Advanced — the default error path that decides where the flow goes if the script fails.
- Events — tracking events that fire when the node runs, to feed your metrics.
Editor configuration
The code editor bundles tools to speed up writing and debugging:- Format: applies Prettier to your script and automatically adds
awaiton asynchronous methods that need it. - Cheat sheet: opens a quick reference with the available global objects (
$context,$memory,$user,$message,$input,$output,$utils) and their methods. - Autocomplete: as you type
$, the editor suggests the available functions and namespaces along with their description. - Light / dark mode: switch the editor theme from the selector in the top-right corner.
- Live validation: the editor flags common lint errors and warns when
awaitis missing on an asynchronous method.
Accessing variables
Inside the Code node you can read and write flow variables using predefined global objects.Context ($context)
Variables that persist only during the current flow execution:
Memory ($memory)
Variables that persist across workflows, tools, and nodes. They support time-to-live (TTL):
Reading
Deletion
Limits by data type
Migration from legacy nodes
- Create a new Code (Memory V2) node.
- Copy and paste the script from the legacy node.
- Use the new available methods (
$memory.setJson,$memory.setFile, etc.) if needed.
User ($user)
Information about the contact interacting with your flow:
Message ($message)
The last message sent by the user:
Input/Output ($input, $output)
For communication between tools and workflows:
HTTP responses
If you saved the response from an API node:Available utilities ($utils)
Logger
Logs values for debugging in key-value format. Logs appear in the execution history:Crypto
Standard cryptographic functions:Lodash
Utilities for manipulating arrays, objects, and strings:DLP (Data Loss Prevention)
At the bottom of the Configuration tab you’ll find the DLP section, which automatically masks sensitive data that the node writes to logs. Turn on the “Enable DLP” toggle to choose which types of information are masked (card number, email, phone number, etc.). It’s the recommended protection whenever your script handles personal, financial, or identity data.Advanced tab
Configure the default error path. If the script throws an uncaught exception (for example, invalid JSON or a missingawait), the flow continues through the configured path instead of stopping. Use it to show a friendly message to the user or to escalate to a human when the script fails.
Events tab
Register tracking events that fire when the node runs. They feed your metrics and let you correlate the execution of this node with conversions or drop-offs. Check the Events guide to learn how to configure and consume them.Use cases
Extract fields from the object saved by an AI Agent
Extract fields from the object saved by an AI Agent
A workflow where an AI Agent node generates a structured response (for example, a JSON with
intent, product, and sentiment) and saves it to context with the Save response option enabled. The following Code node reads that object, validates its fields, and puts them into individual variables so downstream nodes can react without calling the model again.Normalize the response from an API node
Normalize the response from an API node
A workflow where an API node returns a list of orders with field names in English and downstream nodes expect them in Spanish. The Code node transforms the response before continuing.
Validate and mask sensitive data
Validate and mask sensitive data
A workflow where an earlier Question node collected the user’s email and saved it to context. The Code node validates and masks it before storing or displaying it, returning only what’s strictly needed.
Split a list into batches for processing
Split a list into batches for processing
A workflow that needs to process a large list (for example, 300 contacts) by calling an API that only accepts 50 per request. The Code node splits the list into batches and stores them in memory so a downstream node can iterate over them.
Next steps
AI Agent node
Configure an agent and save its response to context so you can process it with Code.
API node
Call external services and read the response with
$context.getHttpResponse().Context variables
How the flow’s temporary variables you read with
$context work.Memory variables
Persist data across workflows, tools, and conversations.