Overview
The CodeViaConfig node allows users to execute custom JavaScript code within their n8n workflows. It is highly flexible and can be used for data transformation, enrichment, filtering, or any logic that can be expressed in JavaScript. The node supports two execution modes: running the code once for all input items or running it separately for each item.
Common scenarios:
- Data formatting or restructuring before sending to another service.
- Filtering or mapping incoming data based on custom logic.
- Enriching items with additional computed fields.
- Integrating with external libraries (if available in the sandbox).
Practical examples:
- Extracting specific fields from a JSON object.
- Calculating new values based on existing item properties.
- Aggregating data across multiple items.
Properties
| Name | Type | Meaning |
|---|---|---|
| Mode | options | Determines how the JavaScript code is executed: - Run Once for All Items: Code runs a single time, receiving all input items. - Run Once for Each Item: Code runs individually for each input item. |
| JavaScript | string | The JavaScript code to execute. You can use special variables (e.g., $today, $jmespath) and methods provided by n8n. Debugging is possible via console.log(). |
| Notice | notice | Informational property providing tips and links to documentation about available special variables/methods and debugging techniques. No effect on execution. |
Output
- The output is an array of items, each containing at least a
jsonfield. - The structure of the
jsonfield depends entirely on the user's JavaScript code. - If an error occurs and "Continue On Fail" is enabled, the output will include an item like:
{ "json": { "error": "Error message here" } } - If the user code returns binary data, it will be included in a
binaryfield alongside thejsonfield.
Dependencies
- No external services or API keys are required.
- The node relies on n8n's internal sandboxing mechanism for secure code execution.
- Special variables and helper methods are available as documented in n8n's code node reference.
Troubleshooting
Common issues:
- Syntax errors in JavaScript code: Will result in an error message in the output if "Continue On Fail" is enabled, or stop execution otherwise.
- Reference errors: Using undefined variables or methods not available in the sandbox will throw errors.
- Unexpected output structure: If your code does not return the expected object format, downstream nodes may fail.
Common error messages:
"error": "Unexpected token ..."— Indicates a syntax error in your JavaScript code. Double-check your code for typos or missing characters."error": "Cannot read property 'xyz' of undefined"— You're trying to access a property on an undefined variable. Add checks or ensure the variable exists."error": "is not defined"— A variable or function is not available in the sandbox. Refer to the special variables/methods documentation.
How to resolve:
- Use
console.log()statements for debugging; view logs in the browser console during manual executions. - Review the documentation for available helpers and context variables.