- Bot & Beyond
- Posts
- N8N Code Node For Non Coders
N8N Code Node For Non Coders
Here's how to use the code node without coding

You are no coder, but that's ok. I will show you how to use the code node without coding!!!
First, let's look at the power of code node. The reason I’m in love with it!
The Code Node in n8n
The Code Node in n8n allows users to write custom JavaScript code within workflows.
Here's what the n8n code node can do for you
Transform Data: Format dates/numbers/text, convert JSON structures, merge/split arrays
Advanced Logic: Build multi-step calculations, dynamic filters, and complex if-else conditions
API Handling: Extract specific fields, reshape responses, manage nested data, send custom requests (headers/OAuth/raw payloads)
Iteration: Process batches, loop arrays for complex operations
Math & Stats: Run calculations, aggregate numbers, analyze data
Error Control: Implement try-catch blocks, log debug details
Extend Functionality: Integrate third-party libraries (encryption, hashing, compression)
If you still think “why should I bother”, here's why...
It offers you:
Flexibility: Solve edge cases beyond built-in nodes
Efficiency: Simplify workflows by replacing multiple nodes
Customization: Supports unique business logic tailored to your needs
Speed: Process data faster than chained standard nodes
Debugging: Allows detailed logging and testing within n8n
TL:DR
The Code Node in n8n gives you so much power over your workflows!
Now let's look at how it works
The code node runs inside a sandboxed JavaScript environment to ensure security and prevent malicious operations.
The Code node receives data from upstream nodes as an array of objects (one object per item).
Example input structure:
[
{
"json": { "name": "Alice", "age": 30 }, // Your data
"binary": {}, // Files (if any)
"pairedItem": { ... } // Metadata
},
...
]
You can write code to transform, filter or do anything with this data.
When writing code in this node, there are 2 modes.
Run Once for All Items: Code runs once, processing all items at once.
Run Once for Each Item: Code runs separately for each item (default).
you can select this in Mode dropdown.

It also give you a simple code template for each mode as you select it.

Run Once for All Items

Run for Each Item
Let’s look at an example
Here’s the output of a node you want to manipulate with code node
[
{
"id": 1,
"name": "Alice",
"email": "[email protected]",
"role": "admin"
},
{
"id": 2,
"name": "Bob",
"email": "[email protected]",
"role": "editor"
},
{
"id": 3,
"name": "Charlie",
"email": "[email protected]",
"role": "viewer"
}
]
When you add a code node to the workflow, this data is the input to that code node.
Inside code node, this data can be access in two different ways depending on the mode you want to process data, i.e. Run once for all or Run once for each.
You should always return an object or an array from the code node depending on the mode.
Run Once for All Items
$input.all()
- represents the whole JSON above.
If you simply add the return statement only in the code you can see the output.
return $input.all();

If you want to add another field to each data item, a date for example, here’s how you do it.

// Loop over input items and add a new field called 'date' to the JSON of each one
for (const item of $input.all()) {
item.json.date = $now;
}
return $input.all();
In above code it goes through each of the items in the input and add a date.
item.json
represent each item.
{
"id": 1,
"name": "Alice",
"email": "[email protected]",
"role": "admin"
}
You can add any field you like to each item by giving it a name and attaching it to the end of the item.json.
Example:
item.json.department = "Medical";
Output:
{
"id": 1,
"name": "Alice",
"email": "[email protected]",
"role": "admin",
"department": "medical"
}
And finally you have to return $input.all()
so that the data is available to the next node.
But where does the $now
comes from?
There are a set of built in methods and variable in n8n.
In code node, you can type $
and then a list will appear with all the functions and variables you can use. You can traverse each one of them with up down arrow keys to see a description of it to the right.

This is all the basics you should know to comfortably use the code node. The rest can be outsourced 😉
How to get the JavaScript code for a code node without coding?
I found a genie who does this for me and I’m sharing it with you!
It’s a custom GPT that helps with n8n workflows which you can use for free.
You could simply explain your scenario or logic to the n8n assistant, give it sample input JSON and expected output. It will then generate the code for you.
If you encounter any errors, this GPT can help you troubleshoot that as well.
I don’t know the creator of this custom GPT but I’m so very grateful for that person for creating and sharing it with us.
Now, my job is done. I don’t need to create any more content on n8n… You have the n8n Assistant.
Happy coding!