npx skills add ...
npx skills add n8n-io/skills --skill n8n-code-nodes
npx skills add n8n-io/skills --skill n8n-code-nodes
Use when the user reaches for a Code node, mentions writing JavaScript or Python in n8n, or any custom logic comes up in workflow design. Triggers on "Code node", "Code", "JavaScript", "Python", "custom logic", "transform data", "$input", "$json transformation", "loop in code", "write a function", or any time the obvious answer seems to be "just put it in code.
The Code node is powerful and often the wrong tool. The n8n equivalent of dropping into raw SQL when an ORM would do: real cases exist, but the moment a Code node handles logic an expression could, the workflow is harder to read, debug, and maintain. There's also a real perf gap: Code runs in a sandboxed JS runtime, expressions and Edit Fields run in-process, and the per-invocation overhead can be hundreds of times higher in Code (anecdotally ~2ms vs ~600ms for equivalent logic). For hot paths and large item counts, that compounds.
Code node is a last resort. Decision order: expression ({{...}}) → arrow function inside Edit Fields → Code node. The first two paths cover most "transform this data" tasks. Code earns its place for multi-source aggregation, external libraries, and a few specific patterns documented below.
Default to JavaScript. Write JS unless the user explicitly asked for Python ("use Python here," "I'm a Python shop," pasted Python code). Everywhere else in n8n (expressions, Edit Fields) is JS, JS has a curated library allowlist (lodash, crypto, luxon).
For the full decision logic with examples for each branch, see references/DECISION_TREE.md.
Common reaches-for-Code-node that should be expressions:
For more on what expressions can express, see the n8n-expressions-official skill.
Edit Fields assigns field values via expression. Inline arrow functions get you most multi-line logic without the Code node:
Right tool for "logic slightly too gnarly for a one-liner." See references/ARROW_FUNCTIONS_IN_EDIT_FIELDS.md for patterns and formatting.
Real uses exist. Bar is high, not "never." The cases below are legitimate. Build with code without apologizing.
When a node needs to:
$('Source A').all(), $('Source B').all(), $('Source C').first().json).Most common valid case. Examples:
Technically expressions can reach across items via $('Node Name').all() and reduce inline, but for anything with this much shape (joins, group-bys, nested aggregation) the result is a one-line megaexpression that's hard to read and impossible to debug. Use Code.
JS Code can require from a curated allowlist (lodash, etc.), but expressions can't.
Always check for a native node first. n8n has more native nodes than people realize. Dropping into Code for something with a native node is a recurring mistake. The next two subsections cover the specific traps.
HMAC, signing, hashing, encryption: n8n has a native Crypto node (n8n-nodes-base.crypto). Use it. It handles SHA256, MD5, HMAC, encrypt/decrypt, and random generation, all without writing JavaScript.
The Code-with-require('crypto') pattern is one of the most common false positives for "this needs a Code node." It doesn't. The Crypto node covers it.
Don't reach for Code just because you need to hash binary (a PDF, an image, a file buffer). The Crypto node has a binaryPropertyName parameter. Point it at the binary slot key and it hashes the buffer directly. You don't need this.helpers.getBinaryDataBuffer(...) in user code.
The remaining valid Code-for-crypto case: a non-standard signing scheme that the Crypto node doesn't expose (e.g., a custom AWS-style signature), AND httpCustomAuth credential doesn't fit either. Rare. Justify explicitly.
n8n has a native XML node (n8n-nodes-base.xml) with parse and stringify operations. It already converts XML to JSON. Once it has, the result is plain JSON and Edit Fields with arrow function expressions handles all the field extraction, array normalization (Array.isArray(...) ? ... : ...), and link-finding (.find()) you'd reach for Code to do.
If the field-extraction logic is genuinely too gnarly for inline expressions even with multi-line arrow functions, the next stop is Edit Fields with a single multi-line arrow function, NOT a Code node. See references/ARROW_FUNCTIONS_IN_EDIT_FIELDS.md.
Valid cases are about scope: whole-dataset, multiple sources, or stateful constructs single-item tools can't reach. Invalid cases: Code doing what an expression could, OR what a native node already does.
Quick tests:
search_nodes first. Crypto, XML, JSON parsing, date math (Luxon), HTTP calls, file I/O, regex matching: all have native nodes or expression-level support.Two modes:
$input.all(). If you need per-item logic, just for (const item of $input.all()) inside. This is the standard shape and almost always what you want.$input.first() (or $input.item).Common shape:
The return must be an array of { json: ... } objects (or { json: ..., binary: ... }), not raw JSON.
For binary handling, error patterns, and Code-node-only bugs, see references/JAVASCRIPT_PATTERNS.md.
| File | Read when |
|---|---|
references/DECISION_TREE.md | You're tempted to use a Code node and want to verify the simpler paths really don't work |
references/ARROW_FUNCTIONS_IN_EDIT_FIELDS.md | The transformation is multi-line but pure data shaping |
references/JAVASCRIPT_PATTERNS.md | Code node is genuinely needed and JS is the language |
| Anti-pattern | What goes wrong | Fix |
|---|---|---|
Code node doing return { x: $input.first().json.x.toUpperCase() } | Whole node for one expression | Replace with an Edit Fields expression |
| Code node building HTML strings for an email body | The Email node's body field accepts expressions | Inline the expression into the email node |
Code node using new Date() for date formatting | Loses to Luxon's clarity | Use Luxon in expression. See n8n-expressions-official |
| Set node + Code node combo (Set builds inputs, Code transforms) | Two nodes for what should be one Edit Fields | Collapse into one Edit Fields with arrow function |
| Pasting credentials/tokens into Code node text | Same leak as text fields | Use credentials, not Code node |