$env variable is empty

Describe the problem/error/question

According to the docs, n8n has a meta variable $env that should output all ENVs that have been configured on the instance. But it is empty in both Edit Fields Node or Code node.

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.27.3, 1.34.2
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Docker

The $env variable does not return all set environment variables via an object, rather it allows you to access specific ones. So if you for example want to access the environment variable “MY_VAR” you can do that via:

{{ $env.MY_VAR }}
2 Likes

That was not obvious :sweat_smile:

And I suppose it won’t return the default values? E.g. $env.N8N_HOST if I didn’t set it

Yes, we can for sure make that clearer :wink:

That is correct. It returns only data that is actually set as an environment variable. Under the hood, all it does is access the data from process.env.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.