09 · data
Run JavaScript (or Python where enabled) to transform items in-graph.
When to use it
When Set/IF aren’t enough. Keep Code short — heavy jobs belong in a service you call via HTTP Request.
Writeup
Run JavaScript (or Python where enabled) to transform items in-graph. When Set/IF aren’t enough. Keep Code short — heavy jobs belong in a service you call via HTTP Request.
Step by step — how to wire it
01
Add Code
Place after Schedule or HTTP when you need custom shaping.
02
Write a tiny return
Start with return [{ json: { ok: true } }]; then expand fields.
03
Fan out if needed
Connect Code to Sheets and Slack in parallel for digests.
04
Replace demos
Swap hard-coded KPIs for real reads once credentials exist.
How it functions
Return items
Typical JS: return [{ json: { leads: 12, … } }]; — one or many items.
Reads input
Use $input.all() / items from previous nodes depending on mode.
Used for
Used for 1
Aggregating KPIs for digests
Used for 2
Custom parsing when no node exists
Used for 3
Light business logic without leaving n8n
Tips
Avoid secrets in Code — use credentials on HTTP nodes instead.
Unit-test logic outside n8n if the script grows past ~40 lines.