मुख्य सामग्री पर जाएँ
Skillpedia
ऑटोमेशन6.6k · #13868

n8n-code-javascript

यह क्या करती है

यह स्किल n8n वर्कफ़्लो के अंदर छोटे JavaScript स्निपेट लिखने या ठीक करने में मदद करती है। यह n8n में काम अपने-आप करने वाले और कस्टम डेटा हैंडलिंग चाहने वाले लोगों के लिए है।

कब इस्तेमाल करें

  • ✓जब n8n वर्कफ़्लो में Code नोड पहले से हो और उसे बदलना या ठीक करना हो।
  • ✓जब Code नोड चाहिए, लेकिन कोई बिल्ट-इन n8n नोड काम नहीं कर सकता।
  • ✓जब n8n Code नोड धीमा हो, या वर्कफ़्लो को बहुत सारे आइटम तेज़ी से संभालने हों।

Skill का लिंक

https://github.com/czlonkowski/n8n-skills/blob/main/skills/n8n-code-javascript/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/czlonkowski/n8n-skills/blob/main/skills/n8n-code-javascript/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे n8n Code नोड में जब कोई फ़ील्ड खाली होता है तो एरर आती है, क्या आप JavaScript ठीक कर सकते हैं?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह एजेंट से पहले जाँचवाती है कि क्या कोई बिल्ट-इन नोड या छोटा एक्सप्रेशन काम कर सकता है, और सिर्फ़ उन कामों के लिए JavaScript लिखती है जिन्हें सच में उसकी ज़रूरत है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

JavaScript Code Node

Expert guidance for writing JavaScript code in n8n Code nodes.


Before you write a Code node

A new Code node has to pass this gate first:

  1. Is there a native node for the job? Check the job-to-node table in using-n8n-mcp-skills: Filter, IF / Switch, Summarize, Aggregate, Split Out, Merge, Compare Datasets, Remove Duplicates, Sort + Limit, Date & Time, XML / HTML / Extract From File / Convert To File, HTTP Request (pagination, batching) and Crypto cover most reaches for Code. Their configs are in n8n-node-configuration → NATIVE_NODES.md.
  2. Would a short expression in that node do? One expression, no function body — the helper methods (.pluck(), .sum(), .unique(), $ifEmpty(), .diffTo()) are in n8n-expression-syntax and, on n8n-mcp 2.97.0+, in tools_documentation({topic: "expression_helpers"}). Several statements inside {{ }} count as code, so they belong here rather than in an Edit Fields field.
  3. Is the job on the closed list? Loops or recursion no node expresses, state across runs ($getWorkflowStaticData), parsing no node handles, an allowlisted library, heavy all-items work (thousands of items, stated or measured), or one short Code node (~15 lines) replacing 4+ glue nodes that only reshape data.

If it passes, write the Code node and give it a note, so the next reader (and the review hooks) can see why:

{ "name": "Flatten category tree", "type": "n8n-nodes-base.code", "notes": "Why Code: Split Out considered — the tree has arbitrary depth (recursion)", "notesInFlow": true }

Editing or debugging a Code node that is already there doesn't need the gate, but if the node does a native-node job, say so and offer the native replacement.


Quick Start

// Basic template for Code nodes
const items = $input.all();

// Process data
const processed = items.map(item => ({
  json: {
    ...item.json,
    processed: true,
    timestamp: new Date().toISOString()
  }
}));

return processed;

Essential Rules

  1. Choose "Run Once for All Items" mode (recommended for most use cases)
  2. Access data: $input.all(), $input.first(), or $input.item
  3. Return [{json: {...}}] — the canonical, mode-portable form. In Run Once for All Items mode n8n also auto-wraps a bare return {…} object, so that runs too; what genuinely fails is returning a primitive (string/number) or null.
  4. CRITICAL: Webhook data is under $json.body (not $json directly)
  5. Built-ins available: this.helpers.httpRequest() (no auth — the bare $helpers global is undefined in the task-runner sandbox, so $helpers.httpRequest() throws ReferenceError: $helpers is not defined), DateTime (Luxon), $jmespath(). Not available: this.helpers.httpRequestWithAuthentication (deny-listed), $env (when N8N_BLOCK_ENV_ACCESS_IN_NODE=true), require() (unless allowlisted). For anything beyond a trivial unauthenticated GET (auth, pagination, retries), prefer the HTTP Request node and keep Code nodes for pure logic.
  6. Instance-allowlisted libraries: Self-hosted instances can allowlist modules via N8N_RUNNERS_ALLOWED_BUILT_IN_MODULES and N8N_RUNNERS_ALLOWED_EXTERNAL_MODULES (legacy: NODE_FUNCTION_ALLOW_BUILTIN / NODE_FUNCTION_ALLOW_EXTERNAL). If the user says their instance allows specific modules (e.g. axios, lodash, crypto), use them via require() — don't refuse. If unsure, ask or default to built-ins only.
  7. Wrong skill? If you're writing code for a Custom Code Tool attached to an AI Agent (@n8n/n8n-nodes-langchain.toolCode), stop — that node has a different contract (input via query, must return a string, no $input/$helpers). Use the n8n-code-tool skill.

Mode Selection Guide

The Code node offers two execution modes. Choose based on your use case:

Run Once for All Items (Recommended - Default)

Use this mode for: 95% of use cases

  • How it works: Code executes once regardless of input count
  • Data access: $input.all() or items array
  • Best for: logic that needs every item at once and passed the gate above
  • Performance: Faster for multiple items (single execution)
// Example: running balance — each item depends on the ones before it,
// which no native node expresses (Summarize gives one total per group, not a running one)
let balance = 0;
return $input.all().map(item => {
  balance += item.json.amount |
अक्सर पूछे जाने वाले सवाल

क्या मुझे हमेशा Code नोड इस्तेमाल करना चाहिए?

नहीं। स्किल कहती है कि पहले बिल्ट-इन नोड और सरल एक्सप्रेशन आज़माएँ।

क्या यह दूसरे n8n नोड्स में भी मदद करती है?

हाँ। जो काम Filter, Merge और Summarize जैसे बिल्ट-इन नोड पहले से संभालते हैं, उनके लिए स्किल उन्हीं की ओर इशारा करती है।

क्या यह Code नोड में नोट जोड़ती है?

हाँ। स्किल कहती है कि नए Code नोड पर नोट हो, ताकि अगला पढ़ने वाला उसे समझ सके।

जानकारी

लेखक का मूल विवरण

Write, review, or debug JavaScript in an n8n Code node. Use when a Code node is already in the workflow (editing it, fixing an error, choosing its mode, making it faster), or when a new one is justified: no native node fits (check the job-to-node table in using-n8n-mcp-skills first) and the job is on the closed list — loops or recursion no node expresses, state across runs, parsing no node handles, an allowlisted library, heavy all-items work, or one short node replacing 4+ glue nodes. Covers $input/$json/$node in code, this.helpers, Luxon, SplitInBatches loops, cross-iteration data, pairedIte

repo: czlonkowski/n8n-skills

लोकप्रियता

GitHub स्टार
6.6k
रैंकिंग में स्थान
#13868
लाइसेंस
MIT
अपडेट की गई
24/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills