Code — JavaScript over the items — is for what the other steps cannot say: reshaping data, a calculation, a signature. It gets the items that reached it, and passes on the items it returns.
Who can do this
Workspace Admins and Editors. It is a paid step: On any paid plan. You can build and test it now; publishing asks you to upgrade.
Steps
Select + where the code should run. In the step picker, open Code and select Code.
Language is JavaScript.
Under Run, choose:
- Once for all items (the default) — the code runs once, with every item.
- Once for each item — the code runs once per item, with that item.
Write the code in Code. It starts with an example that passes every item on unchanged:
const out = []; for (const item of $input.all()) { out.push({ json: { ...item.json } }); } return out;Select Run this step. Under the editor, Console shows what the code logged and, if it failed, the error with its line.
What the code can use
| Name | What it is |
|---|---|
$input.all() |
Every item coming in, each as { json: { … } }. |
$input.first(), $input.last(), $input.item |
The first, last, and first item. |
$json |
The first item's fields. |
console.log(…) |
Writes a line to Console (also info, warn, error). |
$now, $today |
This moment and today's date, in UTC. |
$uuid() |
A new random id. |
$sha256(text), $hmacSha256(key, text) |
Hashes, as hex. |
$base64Encode(text), $base64Decode(text) |
Base64. |
No network: that is HTTP Request.
What to return
- A list of items —
[{ json: { … } }, …]— or a list of plain objects, each taken as an item's fields. - One object, as one item.
- An empty list passes nothing on, and the steps after it do not run.
Good to know
- Limits: 30 seconds, 64 MB of memory, 100 calls deep, and 5 MB returned. Console keeps 200 lines.
- Values from earlier steps reach the code through
$input.{{ }}is not used inside code. - Code is a paid step, also when skipped. On Free you can build and test it; publishing asks for a paid plan, and a live run of a workflow with it is skipped if the plan changes.
If something goes wrong
| What the run says | Why | What to do |
|---|---|---|
| Line 3 · TypeError: … A value the code reads is missing on an item. Guard it — item.json.text ?? '' — or use Filter before this step. | The code read a field that is missing. | Guard the value, or filter the items first. |
| Line 5 · ReferenceError: … A name is used that was never declared. Check its spelling; $input, $json and console are the ones given. | A name is misspelt or undeclared. | Correct it. |
| The code cannot be read: … / SyntaxError … Check the brackets and quotes near that line. | The code has a typing mistake. | Fix the line named. |
| The code returned nothing. Return a list of items — [{ json: { … } }] — or one object. | There is no return. |
Return the items. |
| The code returned a value, not items. … / Each item the code returns must be an object — { json: { … } }. | It returned a number, text or a list of those. | Return objects. |
| The code ran for more than 30 seconds and was stopped. Look for a loop that never ends. | Too slow, or a loop that never ends. | Fix the loop, or do less per run. |
| The code used more than 64 MB of memory and was stopped. | Too much memory. | Work on fewer items at a time. |
| The code called itself more than 100 deep and was stopped. | Runaway recursion. | Fix the function calling itself. |
| The code returned more than 5 MB. Return less, or split the work. | Too much returned. | Return less. |
| There is no code to run. | Code is empty. | Write some code. |