Steps
Check the mode first
Open the Code node and look at Mode. Run Once for All Items gives you every incoming item in
$input.all()and expects an array back. Run Once for Each Item runs your code once per item, gives you$json(or$input.item.json) and expects one object back. Most Code node errors come from writing code for one mode while the node is set to the other.Return items in the shape n8n wants
Each item is an object with a
jsonkey that holds an object:{ json: { name: 'Ada', total: 42 } }. In All Items mode return an array of those; in Each Item mode return just one. Strings, numbers,null, nested arrays andjson: 'text'all fail.Read the error message
The message names the problem and, with
[item 0]or[line 1], where it happened. Match it against the table below: each row is a real error from a test run, with the fix.Swap fetch and axios for this.helpers.httpRequest
Inside the Code node,
fetchisn't defined andrequire()is blocked unless the admin allows a module.await this.helpers.httpRequest({ url, json: true })works out of the box. For anything bigger, use an HTTP Request node before the Code node instead.Test with the data you really get
Click Execute step on the Code node and look at the input panel on the left: field names are case-sensitive, and a field that is text (
"42") won't add up like a number. UseNumber(...)orJSON.parse(...)where needed.
Copy-paste templates that work
Run Once for All Items (the default): you get every item at once and must return an array.
// Mode: Run Once for All Items
const out = [];
for (const item of $input.all()) {
out.push({ json: { name: item.json.name, total: item.json.price * item.json.qty } });
}
return out; // always an array of { json: {...} }Run Once for Each Item: the code runs once per item and returns one object.
// Mode: Run Once for Each Item
const j = $input.item.json; // or $json
return { json: { name: j.name, total: j.price * j.qty } }; // one object, not an arrayCalling an API from the Code node: fetch and axios aren't available, but n8n's own helper is.
const data = await this.helpers.httpRequest({
url: 'https://api.example.com/items',
json: true,
});
return [{ json: data }];
Every error we got, and the fix
Code node failing with access to env vars denied or process is not defined [line 1]? Use $env and unblock it: see n8n access to env vars denied.
Code node failing with Node ran out of memory? That is the task runner cap, not your code: see n8n out of memory errors.
On 19 October 2026 we ran 23 small workflows in n8n 2.43.7 with n8n execute: a Manual Trigger, a Code node sending two items, the Code node under test, then an Edit Fields (Set) node to see whether the workflow carried on. These are the exact messages n8n printed.
| What the code did | Error n8n showed | Fix |
|---|---|---|
return 'hello'; | Code doesn't return items properly | Return an array of objects, not a string or number. |
No return at all | Code doesn't return items properly | Add return at the end of the code. |
return [null]; or return [[{json:{...}}]]; | Code doesn't return items properly | One flat array, one object per item. |
return [{json: 'text'}]; | A 'json' property isn't an object [item 0] | Put fields inside json: {json: {text: 'text'}}. |
Each Item mode, return [{json:{...}}]; | A 'json' property isn't an object [item 0] | In Each Item mode return one object, without the square brackets. |
return [{json:{a:1}, binary:'x'}]; | A 'binary' property isn't an object [item 0] | Leave binary out unless it holds real binary data. |
$('Missing Node') | Referenced node doesn't exist | Use the exact node name, including case and spaces. Renamed a node? Update the code. |
require('axios') | Module 'axios' is disallowed [line 1] | Use this.helpers.httpRequest, or allow the module on self-hosted n8n. |
require('crypto') | Module 'crypto' is disallowed [line 1] | Set NODE_FUNCTION_ALLOW_BUILTIN=crypto For an HMAC or a hash you may not need code at all: see the n8n Crypto node guide.and restart n8n. |
await fetch(...) | fetch is not defined [line 1] | Use this.helpers.httpRequest (tested below). |
JSON.parse('not json') | Unexpected token 'o', "not json" is not valid JSON [line 1] | The text isn't JSON. Check what the previous node really sent, or wrap it in try/catch. |
For the three doesn't return items properly cases, n8n adds: Please return an array of objects, one for each item you would like to output. For the json cases it adds: In the returned data, every key named 'json' must point to an object.
Traps that don't show an error
- Values from
$getWorkflowStaticData()that never stick between runs: manual runs never save them, and reassigning the variable or a failed run loses them. See n8n static data not saving. - Want an alert when a Code node throws? The error workflow must be published and set in the failing workflow's settings: see n8n error workflow not triggering.
return [];stops the workflow quietly. The Code node succeeds with 0 items and the next node never runs. If the next steps must run anyway, open the Code node's Settings and turn on Always Output Data: in our test the node then sent one empty item and the next node ran once.$input.itemin All Items mode gives you only the first item. With two items coming in,return [{json:{v: $input.item.json.n}}]ran without complaint and returned one item. Use$input.all()in that mode, or switch the node to Each Item.- n8n fixes some shapes for you.
return [{a:1},{a:2}](nojsonkey) came out as two proper items. A singlereturn {json:{a:1}}in All Items mode and a plainreturn {n2: ...}in Each Item mode were also accepted. So if your code "works" withoutjson, that's why; the strict errors above only appear when the shape can't be guessed. - Dates become text.
new Date(0)came out as the string"1970-01-01T00:00:00.000Z". Convert it back withnew Date(...)in later code. - The old
itemsvariable still works in All Items mode (items.map(...)returned both items), so older forum snippets run, but$input.all()is the current way.
Allowing modules (self-hosted n8n)
- Built-in Node modules are blocked by default. With
NODE_FUNCTION_ALLOW_BUILTIN=cryptoset before starting n8n,require('crypto')worked in our test and hashed a string. Use a comma-separated list, or*for all built-ins. - npm packages such as
axiosneedNODE_FUNCTION_ALLOW_EXTERNAL=axiosand the package installed where the code runs. We didn't test external packages, and if you run task runners in external mode (a separate runners container), the variables and packages belong on that container. - We tested on self-hosted n8n only, not n8n Cloud.
Parsing a model reply into JSON? The Structured Output Parser does it without code; its errors are in n8n Structured Output Parser not working.
What we tested, and what we didn't
- All results above come from real runs of n8n 2.43.7 on 19 October 2026, JavaScript Code node version 2, task runner in internal mode.
this.helpers.httpRequestwas tested against a small local test API and returned its JSON as one item. - We didn't test the Python mode of the Code node, the AI code assistant, or n8n Cloud.
$execution.customData.set() in a Code node ignores booleans and objects without an error; details in n8n Execution Data node not saving.
Start from a working agent
FAQ
What does "Code doesn't return items properly" mean in n8n?
Your Code node returned something that isn't a list of items: a string, a number, null, a nested array, or nothing at all because there's no return. Return an array of objects like [{ json: { ... } }].
How do I fix "A 'json' property isn't an object"?
Every json key must hold an object. Change { json: 'text' } to { json: { text: 'text' } }. In Run Once for Each Item mode, also return a single object rather than an array.
Why does my n8n workflow stop after the Code node with no error?
The Code node returned an empty array, so there were no items for the next node. Return at least one item, or turn on Always Output Data in the node's Settings.
Can I use fetch or axios in the n8n Code node?
Not by default: fetch is not defined and require('axios') is disallowed. Use await this.helpers.httpRequest({ url, json: true }), an HTTP Request node, or on self-hosted n8n allow the package with NODE_FUNCTION_ALLOW_EXTERNAL.
What's the difference between $input.all(), $input.item and $json?
$input.all() is every incoming item and belongs in Run Once for All Items mode. $input.item and $json are the current item in Run Once for Each Item mode. In All Items mode, $input.item quietly gives you only the first item.
Related guides
- n8n expression errors and empty values: 29 tests, every message explained
- n8n Execute Command and Read/Write Files errors: 61 real runs, fixed
- n8n XML node not working: parse errors, one item vs array, attributes and Split Out, 39 runs
- n8n HTTP Request node errors: 401, 404, ECONNREFUSED, SSL and 12 more, fixed
- n8n Basic LLM Chain not working? 25 tests, every error decoded
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes