n8n-code-javascript

Write JavaScript code for n8n Code nodes with correct data access and return formats.

1|Updated Jul 20, 2026
One-click install
npx skills add https://github.com/gonzoblasco/ai-developer-stack --skill n8n-code-javascript-gonzoblasco
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: n8n-code-javascript
Source: https://github.com/gonzoblasco/ai-developer-stack/tree/main/tools-automation/n8n-code-javascript
Command: npx skills add https://github.com/gonzoblasco/ai-developer-stack --skill n8n-code-javascript-gonzoblasco

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing JavaScript inside n8n Code nodes often fails due to incorrect return formats, wrong data access patterns, and confusion between execution modes, causing broken workflows and hard-to-debug errors. ## Core Features & Use Cases - Mode Selection Guidance: Explains when to use "Run Once for All Items" versus "Run Once for Each Item" execution modes. - Data Access Patterns: Covers $input.all(), $input.first(), $input.item, and $node references with working examples. - Error Prevention: Documents the top five mistakes including webhook body nesting, missing return statements, and expression syntax confusion. - Use Case: You receive webhook data in an n8n workflow and need to aggregate, filter, and transform it before sending to an API; this Skill provides the correct $json.body access pattern and [{json: ...}] return structure. ## Quick Start Write an n8n Code node script that aggregates all incoming webhook items and returns the total count and sum.

Frequently Asked Questions about n8n-code-javascript

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write JavaScript in an n8n Code node?▼

Access input data with $input.all() or $input.first(), process it with standard JavaScript, and return an array of objects wrapped in a json property like [{json: {field: value}}]. Choose "Run Once for All Items" mode for most use cases.

What is the difference between Run Once for All Items and Run Once for Each Item in n8n?▼

Run Once for All Items executes the code once with access to all items via $input.all(), ideal for aggregation and batch processing. Run Once for Each Item executes separately per item via $input.item, suited for independent per-item operations.

Why is my n8n Code node returning undefined for webhook data?▼

Webhook data in n8n is nested under the body property, so $json.email returns undefined. Access webhook fields with $json.body.email or $input.first().json.body instead.

Can I make HTTP requests inside an n8n Code node?▼

Yes, use the built-in $helpers.httpRequest() method with method, url, and headers options. Wrap the call in try-catch to handle request failures and return errors in the standard [{json: ...}] format.

When should I avoid using the n8n Code node?▼

Avoid the Code node for simple field mapping, basic filtering, or simple conditionals. Use the Set node for mapping, the Filter node for filtering, and IF or Switch nodes for conditionals instead.