# What is the Code node in n8n?

> The Code node in n8n runs your own JavaScript or Python on the items in a workflow. When it helps, and when an expression is simpler.

Source: https://learn.ynteractive.com/content/glossary/code-node · Updated 2026-10-20 · Free from Stepthrough (https://learn.ynteractive.com)

[n8n and automation](https://learn.ynteractive.com/content/glossary#topic-n8n-and-automation) · [AI glossary](https://learn.ynteractive.com/content/glossary)

Quick answer

The Code node in n8n lets you write a short piece of JavaScript or Python that reads the workflow's items and returns new ones. It runs in one of two modes: once for all items together, or once for each item. Use it when no built-in node or expression does what you need.

Last updated October 20, 2026

[Take the free module →](https://learn.ynteractive.com/courses/n8n-beginner/4)Module 4 of the free [n8n for Beginners: Your First Automations](https://learn.ynteractive.com/courses/n8n-beginner) course, about 9 minutes. No account needed.

Updated October 20, 2026 · By [Robert Breen](https://learn.ynteractive.com/content/about)

## Why it matters for a small business

Most office automations never need code: built-in nodes, [expressions](https://learn.ynteractive.com/content/glossary/expression) and the [Edit Fields node](https://learn.ynteractive.com/content/glossary/edit-fields-node) cover formatting, picking fields and simple math. The Code node is the escape hatch for the rest, such as a custom calculation over many rows, reshaping awkward data from an API, or a rule too long for one expression.

It comes with a cost: someone has to read and maintain the code. If the person who wrote it leaves, a small, well-commented Code node is fine, while a long one can become the part nobody dares touch. AI assistants can write the code for you, but test the output against real items before trusting it.

Where you'll use it: in the n8n node panel, search for **Code**. Choose **Run Once for All Items** or **Run Once for Each Item**, pick JavaScript or Python, and write code that returns items. The output panel shows what came back, just like any other node.

## In a real lesson: n8n: Items, JSON and Expressions, Explained by Doing

The free [n8n Items, JSON and Expressions lesson](https://learn.ynteractive.com/content/n8n-items-json-expressions-tutorial) shows why you often do not need the Code node. Clearview Bookkeeping (made up) has five overdue invoices, and you build one reminder line and a late fee that work for every invoice using Edit Fields and expressions.

One quiz in the lesson offers "You need a Code node" as an answer, and it is the wrong one: the real fix is switching a field to Expression. A Code node would make sense if the late fee depended on a long table of rules, but for one formula, an expression is shorter and easier to check.

[Try this lesson free](https://learn.ynteractive.com/modules/n8n-data-and-expressions) or [read the step-by-step guide](https://learn.ynteractive.com/content/n8n-items-json-expressions-tutorial).

## Common confusions

### Code node vs expression

An expression fills in one field with a small formula. The Code node can read and return whole items, and many of them at once.

### Code node vs HTTP Request node

To call an API, use the [HTTP Request node](https://learn.ynteractive.com/content/glossary/http-request-node). It handles credentials and errors without code.

## Tips

- Try an expression or Edit Fields first; reach for code last.
- Add a comment at the top saying what the code does and why.
- Test with the same items each time by pinning the input.

## Related terms

[Expression](https://learn.ynteractive.com/content/glossary/expression) · [Edit Fields (Set) node](https://learn.ynteractive.com/content/glossary/edit-fields-node) · [Item (n8n)](https://learn.ynteractive.com/content/glossary/item) · [JSON](https://learn.ynteractive.com/content/glossary/json) · [Node](https://learn.ynteractive.com/content/glossary/node)

## More n8n and automation terms

[Credential](https://learn.ynteractive.com/content/glossary/credential) · [Credits (Make)](https://learn.ynteractive.com/content/glossary/make-credits) · [Cron expression](https://learn.ynteractive.com/content/glossary/cron-expression) · [Delay by Zapier](https://learn.ynteractive.com/content/glossary/delay-by-zapier)

## Where you use it: free lessons

- [n8n: Items, JSON and Expressions, Explained by Doing](https://learn.ynteractive.com/content/n8n-items-json-expressions-tutorial) (n8n, 9 min)
- [n8n: Call Any API with the HTTP Request Node](https://learn.ynteractive.com/content/n8n-http-request-node-call-any-api) (n8n, 9 min)
- [ProLevelMax in n8n: Keep Your Reddit Workflow Alive After the RSS Shutdown](https://learn.ynteractive.com/content/prolevelmax-n8n-reddit-rss-replacement) (n8n, 9 min)
- [n8n + Felo: A Monday Research Brief With a Source for Every Answer](https://learn.ynteractive.com/content/n8n-felo-api-weekly-research-brief) (n8n, 9 min)

## Frequently asked questions

**Does the Code node support Python?**

Yes. n8n's Code node supports JavaScript and Python. JavaScript is the default and has the most examples.

**Can I install extra libraries in the Code node?**

On self-hosted n8n you can allow some external modules; on n8n Cloud the choice is limited. Check n8n's docs for your setup.

[All AI glossary terms, A to Z](https://learn.ynteractive.com/content/glossary) · [Free prompt templates](https://learn.ynteractive.com/content/prompts)
