n8n Code Node
n8n's Code node is what separates it from purely no-code platforms. When visual nodes reach their limits — complex data transformations, custom calculations, dynamic logic — the Code node lets you write JavaScript or Python to handle it. This guide covers how to use the Code node effectively, from basic data manipulation to complex transformations.
When to Use the Code Node
The Code node is appropriate when:
Complex data transformation: You need to reshape data in ways that visual nodes can't express — merging arrays from multiple sources, creating nested structures, normalising inconsistent data formats.
Custom calculations: Math operations beyond what expression nodes support — running totals, statistical calculations, date arithmetic with business logic.
Dynamic logic: Logic that depends on the data itself — if the array has more than 10 items, process it differently; iterate over a dynamic number of items; group data by a calculated key.
Parsing custom formats: Extracting data from non-standard formats — custom string formats, legacy data structures, inconsistently formatted imports.
AI response processing: Cleaning and validating AI model outputs before passing to downstream nodes.
Code Node Basics
The Code node receives data from the previous node and returns transformed data to the next node.
Input: $input.all() returns all items from the previous node. $input.first() returns the first item. Each item has a json property containing the data.
Output: Return an array of objects, each with a json property:
Access previous nodes: $node['Node Name'].json gives you access to any previous node's output.
Common Code Node Patterns
Add computed fields:
Filter items:
Aggregate data:
Group by field:
Parse AI JSON output:
Date manipulation:
Async Operations in Code Nodes
For operations that require async/await (HTTP calls, delays):
Using $http within a Code node allows HTTP calls without a separate HTTP Request node — useful for inline data fetching during complex transformations.
Python Code Node
n8n also supports Python in the Code node (select Python from the language dropdown). Python is useful for:
- Data analysis with pandas-style operations
- Mathematical computations
- Engineers more comfortable with Python than JavaScript
Python access pattern:
Recommended Tools
- n8n — Platform with Code node capability
- Claude API — AI output that Code nodes often parse and transform
- n8n Community — Examples and solutions for Code node patterns
- Airtable — Destination for transformed data
“The Code node is n8n's superpower. It transforms n8n from a visual automation tool into a complete business logic platform. Master it and the only limit is what you can code.”
Related articles
n8n vs Make.com vs Zapier: a 2026 honest comparison
No affiliate fluff — where each tool wins, where it breaks, and what we actually run.
Self-hosting n8n: a production-grade setup guide
Queue mode, workers, backups, and the security defaults you should never skip.
Complete n8n Guide: Everything You Need to Build Powerful Automations
The definitive n8n guide — nodes, credentials, triggers, and production-grade patterns.