When a ready-made step isn't enough
🎯You'll be able to
Decide whether a change needs a ready-made node, an expression or a Code node, and justify the choice.
🏠The everyday picture
A kitchen has a mixer, a grater and a peeler, and most dishes need only those. Now and then a recipe needs something cut in an unusual way, and you pick up a knife. You wouldn't throw away the mixer, and you wouldn't chop everything by hand.
📘What it really is
- n8n gives you three ways to change data, from simplest to most flexible:
- Ready-made nodes such as Set (Edit Fields), IF, Split Out, Aggregate, Sort and Remove Duplicates;
- expressions inside a field, such as
{{ $json.amount_paise / 100 }}; -
the Code node, where you write JavaScript or Python.
-
Reach for code when:
- the logic needs several steps that would take a chain of five or more nodes;
- you need to look across all items at once, for example to group or compare them;
-
the rule is easier to read as a few lines than as a maze of IF branches.
-
Prefer ready-made nodes when they fit. Other people can read them at a glance, and they're easier to change later.
- A good test: if a colleague who knows n8n but not code opens the workflow, can they still follow what happens? Name the Code node clearly, such as "Group orders by customer", and add a note.
📝A worked example
Sharma Textiles wants a daily WhatsApp summary for the owner: total orders, total revenue and the top three products.
| Approach | What it takes | Verdict |
|---|---|---|
| Ready-made nodes only | Aggregate, then Sort, then Limit, then a Set node to build the message, plus a second Aggregate for totals | Works, but six nodes for one message |
| One Code node | About 20 lines that total, group, sort and build the text | Clearer here |
| Expression only | Can't look across all items | Not enough |
You keep the trigger, the sheet read and the message send as normal nodes, and use one Code node named "Build daily summary" in the middle.
🌍Where it's used
- Reports and summaries: totals, counts and top-N lists.
- Messages: building a readable text from many fields.
- Rules: a discount, a priority or a routing decision with several conditions.
- Formats: reshaping data for an API that wants a particular structure.
📝Case scenario
A workflow routes support emails using eleven IF nodes in a row, and nobody can follow it any more. You replace the chain with
one Code node that checks keywords from a small table and returns a team field, followed by a single Switch node on team. The
workflow shrinks from fourteen nodes to five, and adding a new keyword now means editing one table.
🖱️Try it
Look at your order workflow from DA2. Find one place where three or more nodes do one small job. Write down whether a Code node would be clearer, and why. Don't change it yet.
⚠️Common mistakes
- Reaching for code first. Sign: a Code node does what one Set node could. Fix: use the simplest option that's readable to the next person.
- Long chains of nodes for one calculation. Sign: six nodes build one message. Fix: one small, named Code node is clearer here.
🛠️For your project
The inbox router's classification and Project 3's merge rule are good places for a Code node; most other steps are ready-made nodes.
✅Quick check
Name two signs that a Code node is a better choice than ready-made nodes.
Show the answer
The logic would take a long chain of nodes, or it needs to look across all items at once, such as grouping or comparing.
Why prefer ready-made nodes when they fit?
Show the answer
Other people can read and change them more easily than code.
