Overview
This node allows users to run custom TypeScript code within the Deno runtime environment directly inside an n8n workflow. It is designed for scenarios where you need to execute complex or specialized logic that goes beyond standard node capabilities, such as data transformation, calling external APIs with custom logic, or performing calculations.
The node supports two main execution modes:
- Run Once for Each Item: Executes the provided TypeScript code separately for each input item.
- Run Once for All Items: Executes the code once with all input items passed as an array.
Additionally, it offers options to run the code sequentially or in parallel when processing multiple items, allowing optimization of performance based on the use case.
Practical Examples
- Transforming incoming JSON data with custom algorithms.
- Fetching and aggregating data from external services using network permissions.
- Running file system operations or subprocesses securely with fine-grained permission control.
- Implementing conditional logic or loops that are cumbersome to build with standard nodes.
Properties
| Name | Meaning |
|---|---|
| Mode | Determines how the code runs relative to input items: - Run Once for All Items: Run the code a single time with all input items. - Run Once for Each Item: Run the code individually for each input item. |
| Processing | Controls execution style when running per item: - Sequential: Process items one after another. - Parallel: Process all items simultaneously to reduce total execution time. |
| Deno TypeScript Code | The actual TypeScript code to execute in the Deno runtime. This code can access the current item’s JSON data and optionally all items if running in "Run Once for All Items" mode. |
| Permissions | Specifies which Deno runtime permissions to grant to the executing code. Options include: - Allow All - Allow Env (environment variables) - Allow Hrtime (high resolution timing) - Allow Net (network) - Allow Read (filesystem read) - Allow Run (subprocesses) - Allow Write (filesystem write) |
Output
The node outputs JSON data structured as follows:
- When running once per item, each output item corresponds to an input item and contains the result of the executed TypeScript code in its
jsonproperty. - When running once for all items, the output is an array of JSON objects returned by the code.
- If an error occurs during execution for any item and "Continue On Fail" is enabled, the output will include an
errorfield describing the issue alongside the original input data. - Binary data output is not supported or indicated by this node.
Dependencies
- Requires the Deno runtime executable bundled with the node package.
- No external API keys or credentials are inherently required, but the user’s code may require network or filesystem permissions depending on its logic.
- Users must configure appropriate Deno permissions in the node settings to allow the code to perform desired operations safely.
- The node depends on internal helper methods for managing input/output data and error handling within n8n.
Troubleshooting
Common Issues:
- Incorrect permission settings may cause the code to fail when trying to access environment variables, network, or filesystem.
- Syntax errors or runtime exceptions in the provided TypeScript code will cause execution failures.
- Using
.all()method in "Run Once for Each Item" mode throws an error because it is only available in "Run Once for All Items" mode. - Selecting an unknown value for "Mode" or "Processing" properties results in an error.
Error Messages:
"Can't use .all() here": Indicates misuse of the.all()method outside of the allowed mode.- Errors thrown by the user’s TypeScript code will be wrapped and reported with context about the item index.
"Unknown 'Mode' property value"or"Unknown 'Processing' property value": Means an invalid option was selected; verify node configuration."Deno worker terminated or failed to start": Indicates issues initializing the Deno runtime, possibly due to missing executable or resource constraints.
Resolutions:
- Ensure correct permissions are granted matching the code’s needs.
- Validate and test TypeScript code independently before embedding in the node.
- Use "Continue On Fail" option to handle errors gracefully without stopping the entire workflow.
- Confirm the Deno executable path exists and is accessible.
Links and References
- Deno Runtime Manual - Permissions
- TypeScript Official Website
- Deno Official Website
- n8n Documentation - Built-in Methods and Variables (planned support mentioned in code comments)