The visual nodes cover a lot, but sometimes you need a custom step. The Code node lets you write a little JavaScript.
When to use it
Reach for the Code node when you must reshape complex data, calculate something unusual or clean text in ways the Edit Fields node cannot. If a normal node can do the job, prefer it, because it is easier for others to read.
Two modes
You can run the code once for all items or once for each item. “For each item” is simpler for beginners.
What you work with
Your code receives the incoming items and must return items in the format n8n expects, a list of objects with a json field. The editor shows examples.
Safe habits
- Keep snippets short and add comments.
- Do not paste code you do not understand.
- Never put secrets inside code; use credentials.
- Test with realistic and empty data.
AI help
AI tools can draft snippets, but test every line. Wrong code can silently produce wrong data.
Related
Learn the basics first in expressions and JSON.
Quick answers
When should I use the Code node?
When visual nodes cannot do the reshaping or calculation you need.
Is it safe to paste AI-written code?
Only after you understand and test it with realistic data.
Can I store secrets in code?
No. Use credentials.
Related reading
- How to Build Your First n8n Workflow: Form to Sheet to Email
- n8n Webhook Node: Test URL vs Production URL Explained
- How to Use the HTTP Request Node in n8n to Call Any API
Prefer feedback on your own workflows?
In our live n8n classes you build workflows alongside a trainer who reviews your work. It is a practical 15-day program for beginners to advanced learners.
See the 15-day n8n training | Find your city | Book free counselling