
N8n Code Javascript
Install when you build n8n workflows that need Code nodes for custom JavaScript transforms, HTTP calls, or batch-loop logic.
Overview
n8n-code-javascript is an agent skill for the Build phase that teaches correct JavaScript patterns for n8n Code nodes, including input access, return format, loops, and HTTP helpers.
Install
npx skills add https://github.com/czlonkowski/n8n-skills --skill n8n-code-javascriptWhat is this skill?
- Covers $input.all(), $input.first(), $input.item, and mandatory `[{json: {...}}]` return shape
- Documents webhook payload under `$json.body` and Run Once for All Items vs per-item modes
- $helpers.httpRequest(), Luxon DateTime, and $jmespath() without relying on blocked $env/require
- SplitInBatches loop patterns, cross-iteration state, and pairedItem troubleshooting
- Production-oriented error handling and real-world aggregation, filter, and API-call recipes
Adoption & trust: 4k installs on skills.sh; 5.3k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You added a Code node to an n8n workflow but items vanish, webhooks read the wrong fields, or batch loops corrupt pairedItem links.
Who is it for?
Solo builders shipping n8n automations who need custom JS transforms, API calls, or SplitInBatches logic without trial-and-error in the UI.
Skip if: Teams only using drag-and-drop nodes with no Code nodes, or workflows authored entirely in Python or external services outside n8n.
When should I use this skill?
Writing JavaScript in n8n Code nodes, using $input/$json/$node syntax, HTTP with $helpers, DateTime, troubleshooting Code errors, choosing Code modes, or any custom data transformation—including whenever a workflow needs
What do I get? / Deliverables
After the skill runs, your agent emits Code node scripts that follow n8n return contracts, mode choices, and loop-safe patterns ready to paste into the editor.
- Paste-ready Code node script with correct `[{json: ...}]` return
- Mode recommendation (all items vs per item)
- Loop-safe batch processing snippet when applicable
Recommended Skills
Journey fit
Code nodes sit in the integration layer where solo builders wire APIs, webhooks, and data pipelines in n8n. n8n is a workflow integration surface; this skill is the canonical reference for in-node JavaScript, not frontend or infra deploy.
How it compares
Use instead of generic JavaScript snippets that ignore n8n’s `$input` API and required item envelope.
Common Questions / FAQ
Who is n8n-code-javascript for?
Indie operators and developers who automate with n8n and want their coding agent to write Code node JavaScript that actually runs in production.
When should I use n8n-code-javascript?
During Build when wiring integrations—any time a workflow needs a Code node for mapping webhook bodies, calling HTTP APIs, filtering batches, or fixing SplitInBatches pairedItem errors.
Is n8n-code-javascript safe to install?
Review the Security Audits panel on this Prism page and treat Code nodes that call external URLs or handle secrets as part of your own workflow threat model.
SKILL.md
READMESKILL.md - N8n Code Javascript
# JavaScript Code Node Expert guidance for writing JavaScript code in n8n Code nodes. --- ## Quick Start ```javascript // Basic template for Code nodes const items = $input.all(); // Process data const processed = items.map(item => ({ json: { ...item.json, processed: true, timestamp: new Date().toISOString() } })); return processed; ``` ### Essential Rules 1. **Choose "Run Once for All Items" mode** (recommended for most use cases) 2. **Access data**: `$input.all()`, `$input.first()`, or `$input.item` 3. **CRITICAL**: Must return `[{json: {...}}]` format 4. **CRITICAL**: Webhook data is under `$json.body` (not `$json` directly) 5. **Built-ins available**: $helpers.httpRequest() (no auth), DateTime (Luxon), $jmespath(). **Not available**: $helpers.httpRequestWithAuthentication, $env (when N8N_BLOCK_ENV_ACCESS_IN_NODE=true), require() (unless allowlisted) --- ## Mode Selection Guide The Code node offers two execution modes. Choose based on your use case: ### Run Once for All Items (Recommended - Default) **Use this mode for:** 95% of use cases - **How it works**: Code executes **once** regardless of input count - **Data access**: `$input.all()` or `items` array - **Best for**: Aggregation, filtering, batch processing, transformations, API calls with all data - **Performance**: Faster for multiple items (single execution) ```javascript // Example: Calculate total from all items const allItems = $input.all(); const total = allItems.reduce((sum, item) => sum + (item.json.amount || 0), 0); return [{ json: { total, count: allItems.length, average: total / allItems.length } }]; ``` **When to use:** - ✅ Comparing items across the dataset - ✅ Calculating totals, averages, or statistics - ✅ Sorting or ranking items - ✅ Deduplication - ✅ Building aggregated reports - ✅ Combining data from multiple items ### Run Once for Each Item **Use this mode for:** Specialized cases only - **How it works**: Code executes **separately** for each input item - **Data access**: `$input.item` or `$item` - **Best for**: Item-specific logic, independent operations, per-item validation - **Performance**: Slower for large datasets (multiple executions) ```javascript // Example: Add processing timestamp to each item const item = $input.item; return [{ json: { ...item.json, processed: true, processedAt: new Date().toISOString() } }]; ``` **When to use:** - ✅ Each item needs independent API call - ✅ Per-item validation with different error handling - ✅ Item-specific transformations based on item properties - ✅ When items must be processed separately for business logic **Decision Shortcut:** - **Need to look at multiple items?** → Use "All Items" mode - **Each item completely independent?** → Use "Each Item" mode - **Not sure?** → Use "All Items" mode (you can always loop inside) --- ## Data Access Patterns ### Pattern 1: $input.all() - Most Common **Use when**: Processing arrays, batch operations, aggregations ```javascript // Get all items from previous node const allItems = $input.all(); // Filter, map, reduce as needed const valid = allItems.filter(item => item.json.status === 'active'); const mapped = valid.map(item => ({ json: { id: item.json.id, name: item.json.name } })); return mapped; ``` ### Pattern 2: $input.first() - Very Common **Use when**