data/skills/n8n-code-javascript/README.md
Expert guidance for writing JavaScript code in n8n Code nodes.
Teaches how to write effective JavaScript in n8n Code nodes, avoid common errors, and use built-in functions effectively.
Trigger keywords:
Common scenarios:
[{json: {...}}].bodyTop 5 errors to avoid:
{{}} in code)$helpers global is undefined in the task-runner sandbox; prefer the HTTP Request node for anything beyond a trivial unauthenticated GET)n8n-code-javascript/
├── SKILL.md
│ Overview, quick start, mode selection, best practices
│ - Mode selection guide (All Items vs Each Item)
│ - Data access patterns overview
│ - Return format requirements
│ - Critical webhook gotcha
│ - Error prevention overview
│ - Quick reference checklist
│
├── DATA_ACCESS.md
│ Complete data access patterns
│ - $input.all() - Most common (26% usage)
│ - $input.first() - Very common (25% usage)
│ - $input.item - Each Item mode (19% usage)
│ - $node - Reference other nodes
│ - Webhook data structure (.body nesting)
│ - Choosing the right pattern
│ - Common mistakes to avoid
│
├── COMMON_PATTERNS.md
│ 10 production-tested patterns
│ - Pattern 1: Multi-source Aggregation
│ - Pattern 2: Regex Filtering
│ - Pattern 3: Markdown Parsing
│ - Pattern 4: JSON Comparison
│ - Pattern 5: CRM Transformation
│ - Pattern 6: Release Processing
│ - Pattern 7: Array Transformation
│ - Pattern 8: Slack Block Kit
│ - Pattern 9: Top N Filtering
│ - Pattern 10: String Aggregation
│ - Pattern selection guide
│
├── ERROR_PATTERNS.md
│ Top 5 errors with solutions
│ - Error #1: Empty Code / Missing Return (38%)
│ - Error #2: Expression Syntax Confusion (8%)
│ - Error #3: Incorrect Return Wrapper (5%)
│ - Error #4: Unmatched Brackets (6%)
│ - Error #5: Missing Null Checks
│ - Error prevention checklist
│ - Quick error reference
│ - Debugging tips
│
├── BUILTIN_FUNCTIONS.md
│ Complete built-in function reference
│ - this.helpers.httpRequest() API reference
│ - DateTime (Luxon) complete guide
│ - $jmespath() JSON querying
│ - $getWorkflowStaticData() persistent storage
│ - Standard JavaScript globals
│ - Available Node.js modules
│ - What's NOT available
│
└── README.md (this file)
Skill metadata and overview
Total: 6 files
MOST COMMON MISTAKE: Webhook data is under .body
// ❌ WRONG
const name = $json.name;
// ✅ CORRECT
const name = $json.body.name;
Prefer the canonical [{json: {...}}] — unambiguous in both execution modes. A bare object auto-wraps in Run Once for All Items mode, so it runs too; what actually fails is returning a primitive (string/number) or null.
// ⚠️ Auto-wrapped in All Items mode → [{json: {result: 'success'}}]. Runs, but prefer the array form.
return {json: {result: 'success'}};
// ✅ CANONICAL
return [{json: {result: 'success'}}];
Don't use {{}} in Code nodes
// ❌ WRONG
const value = "{{ $json.field }}";
// ✅ CORRECT
const value = $json.field;
{{}} in OTHER nodes{{}})search_nodes({query: "code"})get_node("nodes-base.code")validate_node()Use Code node when:
Consider other nodes when:
Code node excels at: Complex logic that would require chaining many simple nodes
Before this skill:
After this skill:
$input.all(), $input.first(), $input.item[{json: {...}}] (bare objects auto-wrap in All Items mode; primitives/null fail).body property{{}} syntax: Use JavaScript directly5 test scenarios covering:
{{}})Each evaluation tests skill activation, correct guidance, and reference to appropriate documentation files.
Conceived by Romuald Członkowski - www.aiadvisors.pl/en
Part of the n8n-skills collection.