0CodeKit icon

0CodeKit

A toolbox of no-code utilities

Code → Javascript

AI-generated

Overview

The CodeKit node's "Code" resource with the "Javascript" operation allows users to execute custom JavaScript code within an n8n workflow. This is particularly useful for transforming data, performing calculations, or implementing logic that isn't covered by standard n8n nodes. Common scenarios include:

  • Data transformation between steps in a workflow.
  • Custom validation or filtering of incoming data.
  • Generating dynamic values based on input data.

Practical Example:
Suppose you receive a list of user objects and want to add a new field based on existing data (e.g., full name from first and last names). You can use this node to write a small JavaScript snippet to achieve this.

Properties

Name Meaning
Code Your JavaScript code. This is where you enter the script to be executed for each item processed by the node.

Output

  • The output is a JSON object (or array of objects) resulting from the execution of your JavaScript code.
  • The structure of the output depends entirely on what your code returns.
  • If an error occurs and "Continue On Fail" is enabled, the output will contain an error field with the error message as a string.

Example Output:

[
  {
    "result": 42
  }
]

or, in case of error:

[
  {
    "error": "ReferenceError: x is not defined"
  }
]

Dependencies

  • API Key: Requires credentials named codeKitApi to be configured in n8n.
  • No external services are required for the "Javascript" operation itself, but the node as a whole may interact with other resources depending on configuration.

Troubleshooting

Common Issues:

  • Syntax Errors: If your JavaScript code contains syntax errors, the node will throw an error. Check your code carefully for typos or missing characters.
  • Reference Errors: Using undefined variables will result in errors like ReferenceError: x is not defined.
  • Runtime Exceptions: Any exception thrown during code execution will cause the node to fail unless "Continue On Fail" is enabled.

How to Resolve:

  • Double-check your JavaScript code for correctness.
  • Use console.log() statements for debugging if supported by n8n.
  • Enable "Continue On Fail" to capture errors in the output and allow the workflow to proceed.

Links and References

Discussion