Skip to main content
The Code node lets you run custom JavaScript within your flow. It is useful for operations that cannot be achieved with standard nodes: transforming data, performing calculations, manipulating text, signing requests, or integrating custom business logic. The node panel is organized into three tabs:
  • 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 await on 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 await is 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

The methods $memory.setFile(), $memory.getFile().toBase64(), and $memory.getFile().toRaw() are asynchronous. You must use await when calling them.

Migration from legacy nodes

  1. Create a new Code (Memory V2) node.
  2. Copy and paste the script from the legacy node.
  3. 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:
The key in $context.getHttpResponse() must match exactly the one you configured in the “Save response” field of the API node.

Available utilities ($utils)

Logger

Logs values for debugging in key-value format. Logs appear in the execution history:
Each node allows a maximum of 5 log entries. The value of each entry has a limit of 2,000 characters.

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 missing await), 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

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.
Use $utils._.get(obj, 'nested.path', defaultValue) to read nested fields without breaking if the model omits any of them.
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.
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.
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.
Allowed MIME types for $memory.setFile():

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.