n8n code nodes
Use when considering a Code node, writing JavaScript/Python in n8n, fixing Code return shape errors, or deciding between expression, Edit Fields, and Code.
By- name:
- n8n-code-nodes
- description:
- Use when considering a Code node, writing JavaScript/Python in n8n, fixing Code return shape errors, or deciding between expression, Edit Fields, and Code.
n8n Code Nodes
Author: Taghi Molavi
Decision tree
- Can an expression on the consumer node do it? → do that.
- Can Edit Fields + arrow function cover it? → prefer that.
- Need multi-source aggregation, npm-less algorithms, or complex branching on items? → Code.
- Need external libs / long-running jobs? → sub-workflow, custom node, or external service — not giant Code.
Default language: JavaScript. Use Python only if user insists or ecosystem requires it.
Return contract (JS)
Code must return items in n8n shape:
return items.map(item => ({
json: { ...item.json, score: 1 },
pairedItem: item.pairedItem, // preserve when possible
}));
Or:
return [{ json: { ok: true, count: items.length } }];
Common breaks
- Returning raw objects/arrays without
{ json: ... } - Forgetting to handle empty
items - Mutating shared state across runs
- Trying to
requiredisallowed modules - Hiding secrets in code
Run once for all items vs per item
- Per item: simpler expressions pairing
- All items: aggregation, dedup, sort — then output one or many
Pair with
n8n-expressionsfor lighter transformsn8n-debuggingwhen Code "fails silently" (often empty return)
More in this playbook
Safe to turn on
Use this skill when an agent or person is about to create, change or enable an automation inside someone else's account or a shared environment: "create this workflow", "build it in the customer's account", "turn it on", "go live", "deploy this automation". Produces a proposal the human approves, an automation created in the off state, and a short list of what only the human can finish.
Workflow buildingMITn8n agents
Design n8n AI agents the right way. Use when building or editing any @n8n/n8n-nodes-langchain.* AI node — an AI Agent, LLM chain, Text Classifier, or Information Extractor — and whenever the user mentions AI agents, LLM with tools, tool calling, $fromAI, system prompts, agent memory, sessionId, structured/JSON output, output parser, RAG, vector store, a chat assistant/bot, or human-in-the-loop review. Covers Agent-vs-chain-vs-classifier choice, the model/memory/tools/outputParser slots, tool names/descriptions as prompt, structured output with autoFix, memory, RAG, human review, and chat topologies.
Workflow buildingMITn8n agents
Design n8n AI agents the right way. Use when building or editing any @n8n/n8n-nodes-langchain.* AI node — an AI Agent, LLM chain, Text Classifier, or Information Extractor — and whenever the user mentions AI agents, LLM with tools, tool calling, $fromAI, system prompts, agent memory, sessionId, structured/JSON output, output parser, RAG, vector store, a chat assistant/bot, or human-in-the-loop review. Covers Agent-vs-chain-vs-classifier choice, the model/memory/tools/outputParser slots, tool names/descriptions as prompt, structured output with autoFix, memory, RAG, human review, and chat topologies.


