n8n-code-javascript

Write reliable JavaScript for n8n Code nodes with correct return formats.

71|14|Updated Jun 26, 2025
One-click install
npx skills add https://github.com/ProfSynapse/PACT-Plugin --skill n8n-code-javascript-profsynapse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n8n-code-javascript
Source: https://github.com/ProfSynapse/PACT-Plugin/tree/main/pact-plugin/skills/n8n-code-javascript
Command: npx skills add https://github.com/ProfSynapse/PACT-Plugin --skill n8n-code-javascript-profsynapse

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Code node scripting in n8n is easy to misuse without consistent patterns for data access, return formats, and webhook handling. This Skill guides developers to write reliable JavaScript within Code nodes using $input.all(), $input.first(), and $input.item, with built-ins like $helpers.httpRequest and DateTime to build maintainable workflows.

Core Features & Use Cases

  • Pattern-driven data access: use $input.all(), $input.first(), and $input.item to process batches or per-item logic.
  • Reliable return formats: ensure outputs are an array of objects with a json property (e.g., [{json: {...}}]).
  • Webhook-safe data handling: access webhook payloads under .body and guard against missing fields.
  • Built-in utilities: leverage $helpers.httpRequest for API calls and DateTime/Luxon for date/time operations.
  • Use cases: data transformation, API integrations, webhook-driven automations, and per-item validations in both Run All and Run Per Item modes.

Quick Start

  1. Get items through const items = $input.all();
  2. Transform and return with a map: return items.map(i => ({json: {...i.json, processed: true}}));
  3. If needed, perform API calls via await $helpers.httpRequest({method: 'GET', url: 'https://example.com'}); Note: Use plain JavaScript; avoid n8n expression syntax in Code nodes.

Frequently Asked Questions about n8n-code-javascript

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

FAQPage Schema
How do I correctly format return data in an n8n Code node?

Correct return formatting in an n8n Code node requires an array of objects with a json property, like [{json: {...}}]. This structure ensures downstream nodes receive properly parsed items for continued workflow execution.

What is the difference between Run All and Run Per Item modes in n8n Code nodes?

Run All and Run Per Item modes differ in data access: Run All uses $input.all() for batch processing, while Run Per Item uses $input.item for individual item logic. Selecting the appropriate mode ensures safe per-item validations or batch data transformations in n8n.

How do I handle webhook payload data safely in n8n JavaScript?

Webhook payload data in n8n is accessed under the .body property. Guarding against missing fields with safe null checks ensures your webhook-driven automations process incoming HTTP requests reliably without breaking the workflow.

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

Yes, you can make HTTP requests inside an n8n Code node using the built-in $helpers.httpRequest utility. This allows direct API interactions within your JavaScript logic using await $helpers.httpRequest({method: 'GET', url: '...'}).

Does n8n support Luxon or DateTime for date manipulation in Code nodes?

Yes, n8n supports DateTime and Luxon for date and time operations within Code nodes. Leveraging these built-in utilities allows developers to perform reliable date manipulation directly in their JavaScript workflows.

Why does my n8n Code node fail when I use n8n expression syntax in JavaScript?

n8n Code nodes fail with expression syntax because they require plain JavaScript. You must use built-in helpers like $input.all() and $helpers.httpRequest instead of n8n expressions to ensure reliable script execution.