# Code node

A node that runs your own JavaScript to reshape data, filter items or call a library.

AI developers · Part 08: n8n · Card 5 of 13 · Last updated 2026-10-13

## Analogy

The escape hatch, like a custom middleware when no package does quite what you need.

## In an agent

Handy for cleaning an agent's output before it reaches Slack or a database.

## Questions people ask

### What is the n8n Code node for?

The Code node runs your own JavaScript inside a workflow. Use it to reshape data, filter items, compute values or call a small library when no built-in node does quite what you need. It is the escape hatch, like custom middleware when no package fits.

### Should agent logic go in an n8n Code node?

Keep it small there. A Code node is great for cleaning an agent's output before it reaches Slack or a database. Real agent logic, with its loops, tools and tests, belongs in normal code behind an API, where you can version it, test it and debug it properly.

## Related concepts

- [n8n](https://studyvisually.com/learn/tech/ai-developers/n8n/n8n)
- [Trigger node](https://studyvisually.com/learn/tech/ai-developers/n8n/trigger-node)
- [Action node](https://studyvisually.com/learn/tech/ai-developers/n8n/action-node)
- [$json](https://studyvisually.com/learn/tech/ai-developers/n8n/json-item)

Web page: https://studyvisually.com/learn/tech/ai-developers/n8n/code-node
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=code-node
