JavaScript Patterns in n8n
From the n8n cheat sheet · Code Node · verified Jul 2026
JavaScript Patterns
Common code patterns for data transformation
javascript
// Run Once for All Items (default)
const items = $input.all();
return items.map(item => ({
json: {
email: item.json.email.toLowerCase(),
fullName: \`\${item.json.first} \${item.json.last}\`,
total: item.json.price * item.json.quantity
}
}));⚠️ MUST return { json: {...} } - not raw objects!
💡 Use $input.all() for all items, $input.item for per-item mode
📌 Reference other nodes: $("Node Name").all()
🎯 Always use try/catch for error handling