Code Node - Custom JavaScript Execution in ConvyAI Agentic Flow
Overview
The Code node executes a custom JavaScript snippet within the flow. The script can read the current flow context, perform custom computations, and make HTTP calls to external systems. The value returned by the script becomes the node's output for downstream nodes.
Positioning
The Code node has one input and one output. It can be placed anywhere in the flow after a trigger node.
Configuration
The configuration panel includes a JavaScript editor with:
- Syntax highlighting (ES6+)
- Auto-indentation
- Line numbering
Accessing flow context
The flow execution context is injected automatically as the global $ object. Use it to access upstream node outputs and context variables:
const customerId = $('extractData').output.customerId;
const flowName = $context.agentic_flow_name;
return {
greeting: `Processing customer ${customerId}`,
flowName: flowName
};
The $ object is read-only - the script cannot modify the flow state directly.
Available APIs
| API | Description |
|---|---|
fetch | Standard Fetch API for HTTP calls to external systems. |
JSON | Standard JSON utility (JSON.parse, JSON.stringify). |
Math | Standard Math utility. |
Date | Standard Date object. |
import and require are not supported - external libraries cannot be loaded.
Return value
The script must return a JSON object using return. If the script returns undefined or a primitive type, the node fails with:
Invalid Output: Code node must return a JSON object
Execution limits
| Limit | Value | Configurable |
|---|---|---|
| Timeout | 10 seconds | No |
| Maximum memory | 8 MB | No |
These limits are system-level and cannot be changed by the user.
Error behavior
| Scenario | Behavior |
|---|---|
| Script returns non-JSON value | Node fails: Invalid Output: Code node must return a JSON object |
| Timeout exceeded | Node fails: Execution Timeout. Node state → Failed. |
| Unhandled exception in script | Node state → Failed. Error details visible in run log. |
| Syntax error at save time | Node marked as invalid. Flow cannot be saved. |
Key concepts
| Term | Definition |
|---|---|
$ object | Read-only reference to the flow execution context, automatically injected into the Code node script. |
| Sandbox | Isolated execution environment with resource limits and no access to the filesystem or system variables. |