agentsclimarketplace

N8n syntax code node

Skill Impertio-Studio/n8n-Claude-Skill-Package/skills/source/n8n-syntax/n8n-syntax-code-node

21 deterministic Claude AI skills for n8n v1.x workflow automation

Install
npx -y skills add Impertio-Studio/n8n-Claude-Skill-Package --skill n8n-syntax-code-node

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when writing Code node logic in n8n workflows with JavaScript or Python. Prevents misuse of unavailable variables ($itemIndex, $secrets) or restricted modules (fs, http). Covers runOnceForAllItems vs runOnceForEachItem execution, available variables ($input, $json, items), binary data handling, built-in modules, $() node access, Python _ prefix convention, and restrictions. Keywords: n8n, Code node, JavaScript, Python, $input, $json, items, write code in n8n, JavaScript, Python, custom logic, transform items, Code node example..

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.5 KB, as published. Nobody here has run it

n8n Code Node

Complete reference for the n8n v1.x Code node — JavaScript and Python modes, execution models, available variables, binary data, restrictions, and return format.

Quick Reference

AspectDetail
LanguagesJavaScript (Node.js) — always available; Python — requires N8N_PYTHON_ENABLED=true (stable v1.111.0+)
Default modeRun Once for All Items
Return formatMUST return [{json: {...}}] (all-items) or {json: {...}} (each-item)
EnvironmentSandboxed — no filesystem, no HTTP, no $itemIndex, no $secrets, no $parameter

CRITICAL: 5 Restrictions

These restrictions apply to ALL Code node executions. Violating them causes runtime errors.

  1. NO filesystem access — NEVER use fs, path, or any file I/O. Use Read/Write Files From Disk nodes instead.
  2. NO HTTP requests — NEVER use fetch, axios, or http. Use the HTTP Request node instead.
  3. NO $itemIndex — This variable is NOT available in the Code node. Track index manually with a loop counter.
  4. NO $secrets — External secrets are NOT accessible in Code node. Pass secret values through preceding node output.
  5. NO $parameter — Node configuration parameters are NOT available. Hardcode values or pass them as input data.

Execution Mode Decision Tree

Need to write Code node logic?
├── Processing items independently (filter, transform, enrich)?
│   └── Use "Run Once for Each Item"
│       ├── JS: access current item via $input.item.json
│       └── Python: access current item via _item["json"]
├── Need to compare/aggregate across ALL items (sort, deduplicate, summarize)?
│   └── Use "Run Once for All Items" (default)
│       ├── JS: access all items via items array
│       └── Python: access all items via _items list
└── Can a native node do this instead (Set, Filter, Sort, Merge)?
    └── ALWAYS prefer native nodes — they are faster and maintain item linking

Return Format

Run Once for All Items — MUST Return Array

// JavaScript — ALWAYS return an array of {json: {...}} objects
return items.map(item => ({
  json: { name: item.json.name, processed: true }
}));
# Python — ALWAYS return a list of {"json": {...}} dicts
return [{"json": {"name": item["json"]["name"], "processed": True}} for item in _items]

Run Once for Each Item — Return Single Object

// JavaScript — return ONE {json: {...}} object
return { json: { name: $input.item.json.name, processed: true } };
# Python — return ONE {"json": {...}} dict
return {"json": {"name": _item["json"]["name"], "processed": True}}

NEVER return raw data without the json wrapper. The format {json: {...}} is mandatory.

Available Variables

JavaScript Variables

VariableModeDescription
itemsAll ItemsArray of all input items
$input.itemEach ItemCurrent item being processed
$input.all()BothAll input items from current node
$input.first()BothFirst input item
$input.last()BothLast input item
$jsonEach ItemShorthand for $input.item.json
$binaryEach ItemShorthand for $input.item.binary
$("<node>").all()BothAll items from named node
$("<node>").first()BothFirst item from named node
$("<node>").itemMatching(i)BothTrace back to matching item in named node
$execution.idBothCurrent execution ID
$execution.modeBoth"test", "production", or "evaluation"
$execution.customDataBothGet/set custom execution metadata
$workflow.idBothWorkflow ID
$workflow.nameBothWorkflow name
$workflow.activeBothWhether workflow is active
$nowBothCurrent DateTime (Luxon), respects timezone
$todayBothMidnight today (Luxon)
$envBothInstance environment variables
$varsBothUser-defined variables (all strings)
$prevNode.nameBothName of previous node
$runIndexBothHow many times current node has executed
$jmespath(obj, query)BothJMESPath query function
$ifEmpty(val, fallback)BothNull-safe fallback
$getWorkflowStaticData(type)BothPersistent data ("global" or "node")

Python Variables

Python uses _ prefix instead of $:

Python VariableJavaScript Equivalent
_itemsitems
_item$input.item
_input$input
_execution$execution
_workflow$workflow
_env$env
_vars$vars
_jmespath(obj, query)$jmespath(obj, query)
_getWorkflowStaticData(type)$getWorkflowStaticData(type)
_prevNode$prevNode
_now$now
_today$today

Python-specific rules:

  • ALWAYS use bracket notation: item["json"]["field"] — dot notation fails
  • On n8n Cloud: NEVER import external libraries
  • Self-hosted: standard library + allowlisted third-party modules only
  • getBinaryDataBuffer() is NOT supported in Python

Binary Data Handling

// Get binary buffer (JavaScript only, NOT available in Python)
const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, 'data');

// Create new item with binary data from base64
return [{
  json: { fileName: 'output.txt' },
  binary: {
    data: await this.helpers.prepareBinaryData(
      Buffer.from('file content', 'utf-8'),
      'output.txt',
      'text/plain'
    )
  }
}];

NEVER access binary data directly via items[0].binary.data.data. ALWAYS use getBinaryDataBuffer().

Built-in Modules

ModuleAvailability
Node.js cryptoCloud + Self-hosted
moment (npm package)Cloud + Self-hosted
Luxon (via expressions)Cloud + Self-hosted
External npm modulesSelf-hosted only (requires env config)

Item Linking in Code Node

ALWAYS use $("<node>").itemMatching(index) in Code node — NOT $("<node>").item:

// Correct — Code node item tracing
const originalData = $("HTTP Request").itemMatching(0).json;

// Wrong — .item does not work reliably in Code node
// const originalData = $("HTTP Request").item.json;

Error Handling

// Try-catch pattern for Code node
try {
  const value = items[0].json.requiredField;
  if (!value) throw new Error('requiredField is missing');
  return [{ json: { result: value } }];
} catch (error) {
  // Return error as data (workflow continues)
  return [{ json: { error: error.message } }];
}

When NOT to Use Code Node

ALWAYS prefer native nodes for these operations:

OperationUse Instead
Filter itemsFilter node
Set/rename fieldsEdit Fields (Set) node
Sort itemsSort node
Remove duplicatesRemove Duplicates node
Limit itemsLimit node
Split arraysSplit Out node
Merge dataMerge node
Date/time formattingExpressions with Luxon
Simple conditionalsIF / Switch node

Native nodes are faster (no sandbox overhead) and maintain automatic item linking.

Reference Files

Sources

  • n8n Code node documentation: n8n-io/n8n-docs (main branch)
  • n8n Code node source: packages/nodes-base/nodes/Code/Code.node.ts
  • n8n Expression reference: docs/data/expression-reference/
  • n8n Binary data reference: docs/data/specific-data-types/binary-data.md

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.