CodeHarbor icon

CodeHarbor

Execute JavaScript code with dependencies in a Docker container environment

Overview

The node "CodeHarbor" allows users to execute custom JavaScript code within a Docker container environment, supporting the use of external npm packages. It can run user-provided code either once for all input items collectively or once individually for each item. This flexibility makes it useful for scenarios where batch processing or per-item processing is required.

Common use cases include:

  • Transforming or enriching data by running custom logic.
  • Integrating complex computations or third-party libraries not natively supported in n8n.
  • Processing binary data alongside JSON data.
  • Debugging workflows by capturing console logs from the executed code.

For example, you might use this node to apply a custom algorithm to a batch of records or to process each record separately with specific business rules.

Properties

Name Meaning
Mode Determines how the code runs:
- Run Once for All Items: Executes the code once, passing all input items as an array.
- Run Once for Each Item: Executes the code separately for each individual item.
Code The JavaScript code to execute. Must export a function:
- For "Run Once for All Items": function receives an array of items.
- For "Run Once for Each Item": function receives a single item.
Supports console.log for debugging.
Advanced Options Collection of optional settings:
- Cache Key: Unique identifier for caching dependencies.
- Capture Console Logs: Include console output in the node's output.
- Debug Mode: Return detailed debug info.
- Force Update Dependencies: Force reinstalling dependencies.
- Input Items (only for "Run Once for Each Item"): JSON data to pass instead of the default input.
- Process Binary Output: Whether to convert binary data in output for direct usability.
- Timeout: Maximum execution time in milliseconds.

Output

The node outputs an array of items corresponding to the processed results from the executed JavaScript code.

Each output item has the following structure:

  • json: Contains the result of the code execution under the result key. If debug mode is enabled, additional _debug information may be present. If console log capture is enabled, _console contains the logged messages.
  • binary (optional): If the output includes binary data and "Process Binary Output" is enabled, binary data is prepared and attached here for direct use in subsequent nodes.

The node handles both JSON and binary data transparently, converting base64-encoded binary data returned from the execution into usable binary buffers.

Dependencies

  • Requires an external service accessible via an API URL and authenticated with an API key credential. This service executes the provided JavaScript code inside a Docker container.
  • The node configuration must include credentials containing the API URL and authentication token.
  • No local npm package installation is needed; external packages can be used via the remote execution environment.

Troubleshooting

  • Timeouts: If the code takes longer than the specified timeout (default 60 seconds), execution will be aborted. Increase the timeout if necessary.
  • Dependency Caching Issues: If dependencies are not updating as expected, enable "Force Update Dependencies" to reinstall them.
  • Binary Data Processing Errors: Errors during binary data conversion may occur if the output format is incorrect. Ensure that binary data is properly structured with data (base64 string) and mimeType.
  • API Connection Failures: Verify that the API URL and authentication token are correctly configured in credentials.
  • Code Errors: Runtime errors in the user-provided JavaScript code will cause the node to fail unless "Continue On Fail" is enabled, which will then output error details per item.
  • Console Log Capture: Enabling console log capture may increase output size; disable if not needed.

Links and References

Discussion