n8n-code-javascript

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

Updated Feb 2, 2026
One-click install
npx skills add https://github.com/Test-perelman/Mailtrix --skill n8n-code-javascript-test-perelman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-javascript
Source: https://github.com/Test-perelman/Mailtrix/tree/main/n8n-skills/skills/n8n-code-javascript
Command: npx skills add https://github.com/Test-perelman/Mailtrix --skill n8n-code-javascript-test-perelman

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers struggle to implement reliable JavaScript logic inside n8n Code nodes, including proper data access, safe error handling, and correct return formats.

Core Features & Use Cases

  • Guidance on data access patterns: $input.all(), $input.first(), $input.item, and $node references.
  • Built-in utilities: $helpers.httpRequest(), DateTime (Luxon), and $jmespath for JSON queries.
  • Common workflow scenarios: API calls, webhook data handling, data transformation, and error prevention.

Quick Start

Create a Code node set to Run Once for All Items, use $input.all() to read items, implement your transformation, and return the results in the form [{json: {...}}]. For example, map each input item to a new structure and return the array.

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 n8n Code nodes to handle webhook data?

To handle webhook data in n8n Code nodes, access the payload safely through $json.body rather than $json directly, implement safe null checks, and return results formatted as [{json: {...}}] to avoid common data access pitfalls.

What is the correct return format for n8n Code nodes running JavaScript?

The correct return format for n8n Code nodes is an array of objects structured as [{json: {...}}]. When using Run Once for All Items, map your transformed data into this array structure to ensure the workflow recognizes the output.

How do I make HTTP API calls inside an n8n Code node?

Make HTTP API calls inside an n8n Code node by using the built-in $helpers.httpRequest utility. This method allows you to perform external API requests directly within your JavaScript logic without needing a separate HTTP Request node.

What is the difference between $input.all() and $input.first() in n8n?

$input.all() retrieves every item passed into the Code node as an array for bulk transformations, while $input.first() retrieves only the initial item. Choose based on whether your workflow processes all items or just one.

Why does accessing $json directly cause errors in n8n webhook workflows?

Accessing $json directly causes errors because webhook payloads are nested inside the body property. You must access $json.body to safely extract webhook data and prevent null reference exceptions during JavaScript execution.

Can I use Luxon DateTime for date transformations in n8n Code nodes?

Yes, you can use Luxon DateTime for date transformations in n8n Code nodes. The JavaScript environment provides DateTime as a built-in utility, allowing you to parse, format, and manipulate dates directly within your workflow logic.