n8n-code-javascript

Guides writing JavaScript in n8n Code nodes with data access patterns and error prevention.

2|Updated Jan 12, 2026
One-click install
npx skills add https://github.com/mdc159/cbass --skill n8n-code-javascript-mdc159
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-javascript
Source: https://github.com/mdc159/cbass/tree/main/.claude/skills/n8n-mcp-skills-v1.0.0/skills/n8n-code-javascript
Command: npx skills add https://github.com/mdc159/cbass --skill n8n-code-javascript-mdc159

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing JavaScript in n8n Code nodes causes frequent failures from wrong return formats, expression syntax confusion, webhook data nesting mistakes, and missing null checks, which this Skill prevents with tested patterns and references. ## Core Features & Use Cases - Data Access Guidance: Covers $input.all(), $input.first(), $input.item, and $node references, including the critical webhook .body nesting gotcha. - Production Patterns: Provides 10 tested patterns such as multi-source aggregation, regex filtering, CRM transformation, Slack Block Kit formatting, and top-N ranking. - Error Prevention: Documents the top 5 Code node errors (missing return statements, {{ }} expression misuse, incorrect [{json: ...}] wrapper, bracket escaping, null access) with fixes. - Use Case: When building an n8n workflow that aggregates API responses and posts a formatted Slack report, use this Skill to write the Code node correctly on the first attempt. ## Quick Start Ask the AI to write an n8n Code node in JavaScript that aggregates all input items and returns them in the correct format.

Frequently Asked Questions about n8n-code-javascript

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

FAQPage Schema
How do I access data in an n8n Code node with JavaScript?

Use $input.all() for batch processing of all items, $input.first() for single-item operations, and $input.item only in Run Once for Each Item mode. Access fields via the .json property, such as $input.first().json.fieldName.

What return format does the n8n Code node require?

The Code node must return an array of objects where each object has a json property, in the form [{json: {...}}]. Returning a plain object, a value without the json wrapper, or nothing causes validation errors.

Why is my webhook data undefined in the n8n Code node?

Webhook nodes nest the payload under a body property, so $json.name returns undefined. Access fields via $json.body.name, and use $json.query for URL parameters and $json.headers for HTTP headers.

Can I use {{ }} expressions inside n8n Code nodes?

No, expression syntax with double curly braces only works in other nodes like Set or IF. Inside Code nodes, write plain JavaScript such as $json.field, and use template literals with backticks for string interpolation.

How do I make HTTP requests from an n8n Code node?

Use the built-in $helpers.httpRequest() function with method, url, headers, body, and query string options. External npm packages like axios are not available, so this helper is the supported approach for API calls.

When should I use a Code node instead of Set or IF nodes in n8n?

Use a Code node for complex transformations, multi-step conditionals, aggregations across items, or recursive logic. For simple field mapping, filtering, or single conditions, the Set, Filter, or IF nodes are simpler choices.