Deno Code icon

Deno Code

Run custom TypeScript code in Deno runtime

Overview

This node allows users to run custom TypeScript code within a 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, leveraging the power and security model of Deno.

Typical use cases include:

  • Processing or transforming input data with custom scripts.
  • Running code once for all input items collectively or individually per item.
  • Executing asynchronous operations in parallel or sequentially.
  • Utilizing Deno’s permission system to control access to environment variables, network, filesystem, subprocesses, etc.

For example, you might use this node to fetch additional data from an API, perform advanced calculations, or manipulate JSON structures using TypeScript code snippets.

Properties

Name Meaning
Mode Determines how the code runs relative to input items:
Run Once for All Items: Executes the code a single time with all input items as an array.
Run Once for Each Item: Executes the code separately for each input item.
Processing Controls execution style when running code for each item:
Sequential: Runs code one item at a time in order.
Parallel: Runs code simultaneously for all items, reducing total execution time.
Deno TypeScript Code The actual TypeScript code snippet to be executed inside 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 are granted to the executing code. Options include:
• Allow All
• Allow Env (read environment variables)
• Allow Hrtime (high resolution timing)
• Allow Net (network access)
• Allow Read (filesystem read)
• Allow Run (running subprocesses)
• Allow Write (filesystem write)

Output

The node outputs JSON data resulting from the execution of the user-provided TypeScript code:

  • When running once per item, each output item corresponds to the result of the code execution for that input item.
  • When running once for all items, the output is an array of results corresponding to all input items processed together.
  • If an error occurs during execution for an item and "Continue On Fail" is enabled, the output will include an error object alongside the original item data.
  • The output JSON structure depends entirely on what the user’s TypeScript code returns.
  • No binary data output is produced by this node.

Dependencies

  • Requires the Deno runtime executable to be available on the system path or at /usr/bin/deno.
  • Uses a bundled Deno VM implementation to run the TypeScript code securely.
  • The node relies on n8n’s internal helpers for managing input/output data and error handling.
  • Users must configure appropriate Deno permissions depending on their code needs to avoid runtime permission errors.

Troubleshooting

  • Deno executable not found: The node throws an error if it cannot locate the Deno runtime. Ensure Deno is installed and accessible via system PATH or at /usr/bin/deno.
  • Permission errors: If your code tries to access environment variables, network, filesystem, or subprocesses without granting the corresponding permission, it will fail. Adjust the Permissions property accordingly.
  • Code errors: Syntax or runtime errors in the provided TypeScript code will cause the node to throw errors. Use the editor’s syntax highlighting and test code carefully.
  • Unknown Mode or Processing values: If the Mode or Processing property has an unexpected value, the node throws an error indicating the unknown property value.
  • Using .all() method incorrectly: The code supports $input.all() only when running once for all items; otherwise, it throws an error if used in per-item mode.
  • Performance considerations: Running code in parallel may improve speed but could increase resource usage or cause race conditions if the code is not designed for concurrency.

Links and References

Discussion