What problem does it solve?
Code nodes in n8n require correct data access, robust return formats, and safe handling of inputs to unlock complex automation. This guide provides practical patterns for writing JavaScript in Code nodes, how to navigate $input/$json/$node syntax, and how to leverage built‑ins like $helpers.httpRequest and DateTime.
Core Features & Use Cases
- Data access patterns: $input.all(), $input.first(), and $input.item enable batch processing, single-object API responses, and per-item logic.
- Return format discipline: always produce an array of objects with a json property, enabling downstream nodes to consume results reliably.
- Built-in utilities: access HTTP via $helpers.httpRequest, perform date/time operations with DateTime (Luxon), query JSON with $jmespath, and perform persistent storage with $getWorkflowStaticData().
- Gotchas and best practices: correct webhook data structure under .body, avoid using {{ }} expressions in code, and implement null checks and error handling.
- Mode guidance: Run Once for All Items as the default mode; Run Once for Each Item for per-item workflows, with examples.
Quick Start
Create a Code node, use Run Once for All Items, read all inputs with $input.all(), transform them, and return an array of {json} objects.