Environment variables not accessible in self-hosted setup - $env returns empty object

Hello everyone!

Problem

I’m experiencing an issue with accessing environment variables in my self-hosted n8n setup. Expressions like {{$env["TEST"]}}, return null, and $env itself returns an empty object {}.
This used to work before (as referenced in this previous discussion: How to define custom environment variables available in the n8n workflow - #14 by sscarduzio ), but now it seems like environment variables are no longer accessible from workflows.

Information on your n8n setup

  • n8n version: 1.107.3
  • Running n8n via Docker
  • Environment variables are set on the system level

Has anyone encountered this issue recently? Any insights on what might have changed or how to troubleshoot this would be greatly appreciated.

Thanks in advance for any help!

Hey @sasha hope all is good. Welcome to the community.

$env most certainly does work for me. See both syntaxes:


if you would like to expand on what you are trying to captures and how you are setting you variable, please add more details.

UPD:
Also check if N8N_BLOCK_ENV_ACCESS_IN_NODE is either not set or set to false.
see this doc for more info about it.

Pretty sure this can be disabled. Or it might be by default now.
So make sure to check your ENV variables to see if that isn’t the case. :slight_smile:

Good point, I’ve updated the answer to indicate the variable and the doc about it.

Thank you for your help! I’ve set N8N_BLOCK_ENV_ACCESS_IN_NODE to false, but unfortunately that hasn’t resolved the issue yet. I’ll continue experimenting and will post back with the results.

Loop us in, we can try to help along the way. How do you set your env?