RL ROLAND LOPEZ
// 8 min read

n8n Environment Variables Cheat Sheet

Think of an app as one big function: it takes an input and produces an output. The trick of how we build software is that we do not hard-code the inputs. We pass them in through a file full of settings, so we can change how the app behaves without touching its code.

It is a bit like a parametric 3D model. Imagine designing an iPhone where you only define relationships: this side is one quarter of that side, the screen sits this far from the edge. Then you set one real measurement, say one side is 150 millimeters, and the whole shape snaps into place with every proportion correct. Environment variables are those parameters for your app. You set the values and the behavior takes shape, no code required.

For n8n that means you control the database, security, scaling, and networking from a single file. The one you cannot get wrong is the encryption key: it protects your stored credentials, and if you lose it, they are gone for good.

The settings that actually matter

If you only touch a handful, make it these.

VariableWhat it doesTypical value
N8N_ENCRYPTION_KEYEncrypts your stored credentials. Set it before you save anything, and back it upa 64-char hex secret
WEBHOOK_URLThe public https address n8n uses to build webhook URLshttps://n8n.example.com/
N8N_HOSTThe hostname for the instancen8n.example.com
N8N_PROTOCOLThe URL scheme, https when behind a proxyhttps
EXECUTIONS_MODEWhere workflows run: regular for one box, queue to scale outregular or queue
EXECUTIONS_TIMEOUTHard stop per run in seconds, so a stuck loop cannot run forever3600
N8N_CONCURRENCY_PRODUCTION_LIMITCaps how many executions run at once, to avoid spikes20
💡

Back up your N8N_ENCRYPTION_KEY in a secure vault. Lose it and you lose the ability to decrypt every credential you have stored.

Database: SQLite or Postgres

n8n stores its data one of two very different ways, and the choice comes down to whether you run one instance or many.

SQLite is the default. It is a file that lives right next to the app, in the same process, with no network in between. That makes it fast and zero-setup, ideal for local development and a single small instance.

Postgres is a separate database server you reach over the network. You want it the moment you scale: as soon as you run more than one n8n instance, or you switch on queue mode with workers, every instance has to read and write the same shared database, and a file on one machine cannot do that.

When you scale that far you also bring in Redis. In queue mode, the main process drops each execution onto a Redis-backed queue and your worker processes pull jobs from it. Redis is the shared channel that lets the main process and the workers coordinate, while Postgres holds the data they all share.

VariablePurposeExample or default
DB_TYPESelects the database backendsqlite default, postgresdb for scale
DB_POSTGRESDB_HOSTPostgres host namepostgres
DB_POSTGRESDB_PORTPostgres port5432
DB_POSTGRESDB_DATABASEDatabase namen8n or n8n_prod
DB_POSTGRESDB_SCHEMASchema namepublic
DB_POSTGRESDB_USERDatabase usern8n
DB_POSTGRESDB_PASSWORD_FILEPassword from a mounted secret fileuse _FILE, never inline
VariablePurposeTypical value
DB_POSTGRESDB_POOL_SIZEMax pooled connections10 for queue mode
DB_POSTGRESDB_CONNECTION_TIMEOUTConnect timeout in ms30000 on slow links
DB_POSTGRESDB_IDLE_CONNECTION_TIMEOUTIdle timeout in ms60000 for bursty load
DB_POSTGRESDB_SSL_ENABLEDEncrypt traffic to Postgrestrue for remote or managed
DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZEDVerify the server certificatetrue, disable only for tests

Execution: timeouts and data retention

These control how long workflows can run and how much of their history n8n keeps. In production you want strict timeouts and aggressive pruning, or the database fills up with execution logs.

VariablePurposeTypical value
EXECUTIONS_MODEWhere jobs runregular, or queue for scale
EXECUTIONS_TIMEOUTHard stop per run in seconds3600 to kill loops
EXECUTIONS_TIMEOUT_MAXMax allowed per workflow in seconds7200 for long jobs
EXECUTIONS_DATA_SAVE_ON_SUCCESSSave data from successful runsnone in prod
EXECUTIONS_DATA_SAVE_ON_ERRORSave data from failed runsall, for incident review
EXECUTIONS_DATA_PRUNEDelete old execution datatrue in prod
EXECUTIONS_DATA_MAX_AGEHow long to keep data, in hours168 for one week
N8N_CONCURRENCY_PRODUCTION_LIMITMax concurrent executions20 to prevent spikes

Security: protect credentials and the UI

The encryption key guards your secrets, and Basic Auth keeps strangers out of the editor. Lock these down before you expose n8n to the internet.

VariablePurposeTypical value
N8N_ENCRYPTION_KEYEncrypt stored credentialsset before first prod boot
N8N_BASIC_AUTH_ACTIVEGate the UI with Basic Authtrue for small teams
N8N_BASIC_AUTH_USERBasic Auth user nameadmin or a team user
N8N_BASIC_AUTH_PASSWORDBasic Auth passworda long random string
N8N_BLOCK_ENV_ACCESS_IN_NODEStop Code nodes reading env varstrue for shared installs
N8N_COMMUNITY_PACKAGES_ENABLEDAllow community packagesfalse for hardened clusters

Network and webhooks

This is the group that makes public URLs resolve correctly behind a reverse proxy. Get WEBHOOK_URL wrong and your webhooks point at localhost.

VariablePurposeTypical value
N8N_HOSTHost name for URLsn8n.example.com
N8N_PORTInternal port5678
N8N_PROTOCOLURL schemehttps behind a proxy
WEBHOOK_URLPublic base URL for webhooksthe public https address
N8N_PROXY_HOPSTrusted proxy hop countmatch your proxy chain

Queue mode: scaling with Redis workers

When one instance is no longer enough, queue mode spreads executions across separate worker processes. The main process queues jobs in Redis, and the workers pull and run them. This is where Postgres and Redis become required, not optional.

VariablePurposeTypical value
EXECUTIONS_MODESet to queue to distribute loadqueue
QUEUE_BULL_REDIS_HOSTRedis host nameredis service name
QUEUE_BULL_REDIS_PORTRedis port6379
REDIS_PASSWORD_FILERedis password from a secret filerequired on secured Redis
QUEUE_WORKER_CONCURRENCYJobs each worker runs at oncetune by CPU and memory
N8N_DISABLE_PRODUCTION_MAIN_PROCESSRun a container as worker onlytrue on worker containers

A minimal production .env

Copy this, change the secrets, and you have a sane Postgres and queue setup to start from.

# ---- Identity and URLs ----
N8N_HOST=n8n.example.com
N8N_PORT=5678
N8N_PROTOCOL=https
WEBHOOK_URL=https://n8n.example.com/

# ---- Security ----
# Generate once and store in a secret manager, 64 hex chars
N8N_ENCRYPTION_KEY=YOUR_64_HEX_SECRET
N8N_BLOCK_ENV_ACCESS_IN_NODE=true
N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=change-me-now

# ---- Database (Postgres) ----
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/db_password
DB_POSTGRESDB_POOL_SIZE=10

# ---- Executions and retention ----
EXECUTIONS_MODE=queue
EXECUTIONS_TIMEOUT=3600
EXECUTIONS_TIMEOUT_MAX=7200
EXECUTIONS_DATA_SAVE_ON_SUCCESS=none
EXECUTIONS_DATA_SAVE_ON_ERROR=all
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=168
N8N_CONCURRENCY_PRODUCTION_LIMIT=20

# ---- Queue and Redis ----
QUEUE_BULL_REDIS_HOST=redis
QUEUE_BULL_REDIS_PORT=6379
QUEUE_WORKER_CONCURRENCY=5

TZ=UTC
Roland Lopez
Written by
Roland Lopez

Technical founder & AI crack-head

Built by Agent Skynet Better call Roland