Skip to content
MoveWorkflows

Pipedream code steps → n8n Code node

Updated 2026-10-21 · 4 min read

The n8n Code node is where most Pipedream code steps end up. Both run JavaScript, but the shape of the code is different: a Pipedream step is a component with a run({ steps, $ }) method, while the n8n Code node receives items and must return items. This page maps every Pipedream code-step concept to its n8n equivalent, with before-and-after code.

The two models

A Pipedream Node.js code step (Node.js v20):

export default defineComponent({
  async run({ steps, $ }) {
    const body = steps.trigger.event.body;
    if (!body.email) return $.flow.exit("no email");
    $.export("domain", body.email.split("@")[1]);
    return { email: body.email.toLowerCase() };
  },
});

The same logic in an n8n Code node, mode "Run Once for All Items":

const body = $('Webhook').first().json.body;
if (!body.email) return [];
return [{ json: {
  email: body.email.toLowerCase(),
  domain: body.email.split('@')[1],
} }];

Three differences matter:

  1. No component wrapper. The Code node body is the function itself.
  2. Data is items. n8n passes an array of items between nodes, each { json: {...} } (data structure docs). If you return plain objects, n8n adds the json key for you.
  3. Stopping is returning nothing. Returning an empty array means the next nodes get no items and don't run.

Mapping table

Pipedream n8n Code node
defineComponent({ async run({ steps, $ }) {...} }) Code node body (async is allowed)
steps.trigger.event $('Webhook').first().json (use your trigger node's name)
steps.my_step.$return_value $('my_step').first().json
steps.my_step.foo (from $.export("foo", …)) $('my_step').first().json.foo
return value return [{ json: value }]
$.export(name, value) Add name as a field of the returned item
return $.flow.exit("reason") return [] (or an If node before the step)
$.respond({ status, body }) Respond to Webhook node after the Code node
$.flow.delay(ms) Wait node between two Code nodes
$.flow.rerun(...) No equivalent; Wait node and a loop, or Retry On Fail
process.env.KEY $vars.KEY (Cloud Pro/Enterprise, self-hosted Business/Enterprise); Code nodes can't read credentials, so API keys belong on the node that makes the call
this.slack.$auth.oauth_access_token An n8n credential on an HTTP Request or app node
import axios from "axios" HTTP Request node
Any npm import require() only (the Code node doesn't accept ES import). Cloud: crypto and moment. Self-hosted: allow-listed packages
console.log Browser console of the n8n editor

The node reference syntax ($('Node name'), $input.first(), $input.all()) is documented on n8n's reference previous nodes page. $json works in the Code node only in "Run Once for Each Item" mode.

All items or each item?

The Code node has two modes:

  • Run Once for All Items (default): your code runs once and gets every item through $input.all(). Closest to a Pipedream step, which runs once per event.
  • Run Once for Each Item: your code runs per item and uses $json / $input.item. Useful after a node that returns a list, where Pipedream would have needed a loop.

If a Pipedream trigger delivered one event, there is one item, and both modes behave the same.

HTTP calls and npm

Pipedream code steps often call APIs with axios or the @pipedream/platform wrapper. In n8n, the cleanest replacement is an HTTP Request node before or after the Code node: it handles credentials, pagination and retries. n8n's Code node docs say it can't make HTTP requests and direct you to that node.

npm is the other big change. On n8n Cloud the Code node can load only crypto and moment. On self-hosted n8n you install packages in the task runner image and allow-list them. Full setup: npm packages in n8n.

Rewrite or wrap?

There are two ways to move a code step:

  • Rewrite it in the n8n style shown above. Best for short steps and for code you'll keep maintaining.
  • Wrap the original component in a compatibility layer that provides steps and $ inside the Code node. Faster for many steps, and the logic stays as it was tested in Pipedream.

Our converter wraps: each code step becomes a Code node that calls the original run() with steps, $.export, $.flow.exit and $.respond emulated, and step names are kept so references stay valid. In n8n 2.x the Code node sandbox has no fetch, URL, URLSearchParams, AbortController or process, and built-in modules such as fs are blocked unless allow-listed. Our converter inserts a fetch shim built on this.helpers.httpRequest, a helper n8n doesn't document for the Code node, so test every converted code step after import. npm imports are listed in the report, so you know which steps need self-hosted n8n or a rewrite. You can check a single step for free with the code step checker.

Limits worth checking

Pipedream code steps ran with 256 MB of memory by default and up to 750 seconds on paid plans (limits). On n8n Cloud the maximum execution duration depends on the plan; on self-hosted n8n it is your server. Long-running steps (large file processing, slow APIs) deserve a test run with realistic data before you switch traffic.

Next steps

Not affiliated with Pipedream or n8n.

FAQ

Does the n8n Code node support JavaScript and Python?
Yes. The Code node runs JavaScript or Python. Python runs natively through task runners in n8n 2.x.
What is the n8n equivalent of steps.trigger.event?
Read the trigger node's output with $('Webhook').first().json, or $input.first().json if the trigger is the previous node.
What replaces $.export in n8n?
Return the values as fields of the item: return [{ json: { total: 42 } }]. The next nodes read them as $json.total or $('Node name').first().json.total.
Can the n8n Code node make HTTP requests?
n8n's Code node docs say it can't make HTTP requests and point you to the HTTP Request node. Move API calls into HTTP Request nodes where you can.
Can I use npm packages in the n8n Code node?
On n8n Cloud only crypto and moment. On self-hosted n8n you install packages in the task runner image and allow-list them.

Related

Sources