n8n logon8n INTERMEDIATE

n8n

Comprehensive n8n workflow automation cheat sheet covering nodes, expressions, triggers, code patterns, error handling, and deployment.

5 min read
n8nworkflowautomationno-codelow-codeintegrationapiwebhookstriggers

Core Concepts

Workflows & Nodes

Basic building blocks of n8n automation

javascript
💡 Items are always arrays of objects with a "json" key
⚡ Sub-workflow executions do not count toward limits
📌 Trigger nodes start workflows, action nodes do the work
🎯 Use core nodes (IF, Merge, Set) for flow control

Credentials

Managing authentication for external services

bash
🔐 All credentials encrypted at rest with AES256
💡 Prefer OAuth2 over API keys for auto token refresh
⚠️ Never hardcode secrets in Code nodes or expressions
🎯 Rotate credentials regularly for security

Expression Syntax

Accessing Data

Expression variables for accessing workflow data

javascript
💡 Use $json for inline expressions, $input for Code nodes
⚡ $() and $node[] both work for referencing other nodes
📌 $execution.mode tells you if manual, trigger, or webhook
🔍 Always wrap expressions in {{ }} in node fields

Date & Time with Luxon

Built-in date/time manipulation using Luxon

javascript
⚡ $now and $today are Luxon DateTime objects
💡 Use .plus() and .minus() for date arithmetic
📌 .toFormat() accepts custom format strings
🎯 Chain methods: $now.plus({days:7}).toFormat("yyyy-MM-dd")

Data Transformation

String, array, and object manipulation in expressions

javascript
💡 JMESPath is powerful for complex JSON queries
⚡ Use || for fallback values when field might be empty
📌 Ternary operator works: condition ? true : false
🔍 .map(), .filter(), .reduce() work on arrays

Essential Nodes

HTTP Request

Make API calls to any service

yaml
💡 Use predefined credentials instead of hardcoding auth
⚡ Built-in pagination handles offset/cursor automatically
📌 Enable "Full Response" to access status codes
⚠️ Add Wait nodes between requests to avoid rate limits

IF & Switch

Conditional branching in workflows

yaml
💡 Use Switch node instead of nested IF nodes
⚡ IF node is data type aware (string, number, boolean)
📌 Switch has fallback route for unmatched cases
🎯 Name your output paths descriptively for clarity

Edit Fields (Set)

Transform and reshape data structure

yaml
⚠️ Enable "Include Other Input Fields" or unmapped data disappears!
💡 Use dot notation for nested fields: user.name.first
📌 Mode: Manual Mapping for GUI, JSON Output for code
🔍 Transform fields with expressions in values

Merge & Aggregate

Combine data from multiple sources

yaml
⚠️ Merge node can execute BOTH IF branches even if one is empty
💡 Use "Merge By Fields" for SQL-like joins
📌 Aggregate is opposite of Split Out (items → array)
⚡ SQL Query mode (v1.49.0+) enables custom join logic

Code Node

JavaScript Patterns

Common code patterns for data transformation

javascript
⚠️ 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

Static Data & Workflow Variables

Persist data between executions

javascript
⚠️ Static data only persists in PRODUCTION executions!
💡 Use for incremental processing (track last ID)
📌 getWorkflowStaticData("global") for workflow-wide storage
🔍 Custom variables ($vars) are read-only, set in UI

Triggers

Webhook Trigger

HTTP endpoints for external events

yaml
🔐 Always enable authentication for production webhooks
💡 Test URL has live debugging, prod URL always listens
⚠️ Changing path changes URL - update external services!
📌 Max payload size is 16MB

Schedule Trigger

Cron-based workflow scheduling

bash
💡 Use crontab.guru to generate cron expressions
⚡ Timezone: workflow setting > instance setting
📌 Weekdays = 1-5, Sunday = 0 or 7
🎯 Add random delay to avoid thundering herd

Error Handling

Error Handling Patterns

Strategies for handling workflow errors

yaml
💡 Connect red error output to notification nodes
⚡ Create centralized error workflow with Error Trigger
📌 Use exponential backoff: 1s → 2s → 5s → 13s
🎯 Classify errors: retry vs fix vs fail fast

Self-Hosting

Docker Deployment

Run n8n with Docker and Docker Compose

bash
💡 Use PostgreSQL for production (not SQLite)
⚡ Mount ~/.n8n volume to persist data
📌 Set WEBHOOK_URL to your public domain
🔐 Always enable N8N_BASIC_AUTH for security

Environment Variables

Essential configuration for self-hosted n8n

bash
🔐 N8N_ENCRYPTION_KEY is critical - back it up!
💡 Use PostgreSQL for production, not SQLite
⚠️ WEBHOOK_URL must match your actual public URL
📌 Set both TZ and GENERIC_TIMEZONE to same value

Scaling & Performance

Queue Mode

Scale n8n with workers and Redis

bash
⚡ Queue mode: 220+ executions/second possible
💡 PostgreSQL required for queue mode (not SQLite)
📌 Worker concurrency: 10+ parallel workflows each
🎯 1 worker per CPU core is good starting point

Performance Tips

Optimize workflow performance

bash
💡 Use Split In Batches for large datasets (100 at a time)
⚡ Add Wait nodes between API calls to avoid rate limits
📌 Store last processed ID for incremental ETL
🎯 Break 50+ node workflows into sub-workflows

Common Gotchas

Mistakes to Avoid

Common pitfalls and how to fix them

bash
⚠️ Code node MUST return { json: {...} } format
💡 Static data only persists in production runs!
📌 Merge node triggers ALL input branches to execute
🔐 Always enable webhook authentication in production

AI Features

AI Agent & LangChain

Build AI-powered workflows with LLMs

yaml
🤖 Native LangChain integration built-in
💡 Use Ollama for free local LLM execution
📌 Workflow Tool lets AI agent trigger n8n workflows
⚡ Use memory sub-nodes for multi-turn conversations