Skip to content
MoveWorkflows

n8n environment variables: config, $env and $vars

Updated 2026-10-21 · 5 min read

In short
  • Secrets go in credentials. Shared non-secret config goes in Variables ($vars).
  • n8n 2.x blocks $env in nodes by default. N8N_BLOCK_ENV_ACCESS_IN_NODE=false allows it.
  • $vars needs n8n Cloud Pro or Enterprise, or self-hosted Business or Enterprise.
Check my export – free reportRuns in your browser. Nothing is uploaded.
On this page · 8 sections
  1. Three places for values a workflow needs
  2. $env and N8N_BLOCK_ENV_ACCESS_IN_NODE
  3. Variables ($vars)
  4. Configuration variables for self-hosted n8n
  5. Keeping secrets out of plain env: _FILE
  6. External secrets
  7. Debugging checklist
  8. From Pipedream environment variables

"Environment variables" means two different things in n8n. The first is instance configuration. These are the variables you set on a self-hosted n8n container to control ports, URLs, the database and security.

The second is values your workflows read. For those, n8n offers $env, $vars and credentials, and each has its own rules. This page covers both. It includes the 2.x default that blocks $env in nodes.

Three places for values a workflow needs

$env.NAME $vars.NAME Credentials
Where you set it Server environment (Docker, systemd) n8n UI, Variables tab n8n UI, Credentials
Available on Self-hosted Cloud Pro, Enterprise; self-hosted Business, Enterprise All
Readable in expressions Only if not blocked Yes No (you select them on nodes)
Readable in Code node Only if not blocked Yes No, by design
Encrypted at rest No (it's the process environment) No Yes
Good for Instance-level settings (URLs included) IDs, feature flags, short codes API keys, tokens, passwords

The rule of thumb: secrets go in credentials. Non-secret config that several workflows share goes in Variables. $env is for self-hosted setups where your plan has no Variables.

$env and N8N_BLOCK_ENV_ACCESS_IN_NODE

$env exposes the n8n instance's environment variables in expressions and the Code node. One setting decides whether you can use it: N8N_BLOCK_ENV_ACCESS_IN_NODE.

The n8n 2.0 breaking changes set its default to true. That means nodes can't read environment variables. But the env var reference table still lists the default as false (security variables). So the docs disagree. On 2.x, expect access to be blocked, and set the variable yourself.

To allow it:

environment:
  - N8N_BLOCK_ENV_ACCESS_IN_NODE=false
  - API_BASE_URL=https://api.example.com

Then {{ $env.API_BASE_URL }} works in node parameters.

Know the risk first. Once allowed, anyone who can edit a workflow can read every variable in the n8n process. That includes database passwords and the encryption key, if you pass them as plain env vars. This is why access is blocked by default. If you allow it, keep secrets out of the n8n process environment with _FILE (see below). Or don't allow it at all.

Variables ($vars)

Instance owners and admins create custom Variables in the Variables tab (docs). The rules:

  • Keys can be up to 50 characters long, values up to 1000. The docs allow only letters, digits and underscores in keys and values. So values like URLs may be rejected. Check this in your version.
  • A Variable is global (whole instance) or project-scoped (from n8n 1.118.0). A project variable overrides a global one with the same key.
  • All values are strings. $vars.LIMIT is "100", not 100.
  • Variables are read-only in workflows. A missing variable is undefined and doesn't fail the workflow.
// Code node
const region = $vars.REGION;
const limit = Number($vars.PAGE_LIMIT || 100);

Plans with Variables: n8n Cloud Pro and Enterprise, and self-hosted Business and Enterprise. Cloud Starter and the free Community edition don't have them.

Configuration variables for self-hosted n8n

The reference lists dozens of groups (overview). Almost every production instance sets these:

Variable Default Why you set it
N8N_HOST localhost Host name n8n runs on
N8N_PORT 5678 HTTP port
N8N_PROTOCOL http https when n8n is reached over TLS (encrypted HTTPS)
N8N_WEBHOOK_URL – Public base URL for webhooks behind a reverse proxy (2.30.0+; WEBHOOK_URL is the deprecated alias)
N8N_EDITOR_BASE_URL – Public editor URL, used in emails and SSO redirects
N8N_PROXY_HOPS 0 Number of reverse proxies in front of n8n. Needed for IP allowlists
N8N_ENCRYPTION_KEY Random on first launch Encrypts credentials. Set it yourself
GENERIC_TIMEZONE America/New_York Instance timezone for schedules
DB_TYPE and DB_POSTGRESDB_* SQLite Postgres for production
EXECUTIONS_MODE regular queue for queue mode
EXECUTIONS_TIMEOUT / EXECUTIONS_TIMEOUT_MAX -1 / 3600 Default and maximum workflow timeout in seconds
EXECUTIONS_DATA_PRUNE, EXECUTIONS_DATA_MAX_AGE true, 336 h How long execution history is kept
N8N_PAYLOAD_SIZE_MAX 16 (MiB) Size limit for webhook payloads
N8N_BLOCK_ENV_ACCESS_IN_NODE See above $env access

Do webhook URLs in the editor show localhost while n8n sits behind a domain? Then N8N_WEBHOOK_URL is the variable you're missing.

Code node modules

NODE_FUNCTION_ALLOW_BUILTIN allows Node.js built-in modules in the Code node. NODE_FUNCTION_ALLOW_EXTERNAL allows npm packages. In 2.x with external task runners, both belong on the runner container, not on the main n8n container. A task runner is the separate process n8n uses to run Code node code. Details: npm packages in n8n.

Keeping secrets out of plain env: _FILE

You can add _FILE to the end of most variables. n8n then reads the value from that file (basic configuration). With Docker secrets it looks like this:

services:
  n8n:
    image: n8nio/n8n
    environment:
      - N8N_ENCRYPTION_KEY_FILE=/run/secrets/n8n_key
      - DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/db_password
    secrets: [n8n_key, db_password]
secrets:
  n8n_key:
    file: ./secrets/n8n_key
  db_password:
    file: ./secrets/db_password

The secret values don't appear in docker inspect output. Only the file paths do.

External secrets

On Enterprise plans n8n can read secrets from an outside vault: 1Password Connect, AWS Secrets Manager, Azure Key Vault, GCP Secrets Manager, HashiCorp Vault or Infisical. You reference them as $secrets, in credential fields only. For most teams, credentials plus _FILE for instance config are enough.

Debugging checklist

Symptom Likely cause
$env.X is undefined Access is blocked (the 2.x default), or the variable isn't set on this container
$vars isn't offered Your plan doesn't include Variables
The webhook URL shows localhost:5678 N8N_WEBHOOK_URL isn't set
Credentials fail after a redeploy N8N_ENCRYPTION_KEY changed
Schedules are off by hours GENERIC_TIMEZONE isn't set
You changed a variable and nothing happened A restart is needed. Schedule expressions need republishing

From Pipedream environment variables

Pipedream had environment variables for the whole workspace or for one project. They were secret by default. Code read them with process.env.NAME in Node.js and os.environ["NAME"] in Python. Actions used {{process.env.NAME}} (Pipedream env vars).

They aren't included in the workflow export. Secret values can't be viewed in the UI after saving. So get them from the original provider.

Pipedream n8n
Secret env var (API key) Credential
Non-secret env var Variable ($vars), or $env on self-hosted
Project-scoped variable Project-scoped Variable (1.118.0+)
process.env.X in code $vars.X (the Code node has no process)

Our converter rewrites process.env.X in wrapped code steps. It lists every variable each workflow reads, so you know what to create. The Code node compatibility check shows this for one step. The converter report does it for the whole project. The report and 1 workflow are free. Full export: $3 per workflow, $1 each after 50, $19 minimum, one-off. Full secret checklist: Pipedream secrets to n8n.

Not affiliated with Pipedream or n8n.

FAQ

How do I read an environment variable in an n8n workflow?

On self-hosted n8n, use $env.NAME in an expression or Code node. In n8n 2.x access is blocked by default. Set N8N_BLOCK_ENV_ACCESS_IN_NODE=false to allow it. On n8n Cloud, use Variables ($vars) instead.

What is the difference between $env and $vars in n8n?

$env reads the server's environment (self-hosted only). $vars reads custom Variables you create in the n8n UI. They are available on Cloud Pro/Enterprise and self-hosted Business/Enterprise.

Should I put API keys in n8n environment variables?

No. Store them as credentials. Credentials are encrypted, and Code nodes can't read them. Use environment variables for instance configuration and Variables for non-secret settings.

Which environment variable sets the webhook URL in n8n?

N8N_WEBHOOK_URL (from n8n 2.30.0). It sets the public base URL for webhooks behind a reverse proxy. WEBHOOK_URL is its deprecated alias since 2.35.0.

Can I load n8n environment variables from files?

Yes. Add _FILE to the end of supported variables, for example N8N_ENCRYPTION_KEY_FILE, and point it at a file such as a Docker secret.