How to allow env vars access in set fields or credentials via JS expressions?

Describe the problem/error/question

need help with understanding if this can be done as is done inside of code nodes

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.1.1
  • Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker / k8s
  • Operating system: linux

@adarsh-lm Environment variables are available on Self-hosted Enterprise and Pro Cloud plans; with only instance owners and admins being able to create variables. For more information, see Custom variables | n8n Docs

If you do not have access to custom variables, you can manually create them using an Edit Fields node at the start of your workflow.

Hi @adarsh-lm

Since you are using Docker / k8s, the best way to keep your environment secure is to avoid opening global access and instead only expose the specific variables you need.

add this configuration to your deployment:

  • Variable: N8N_EXPRESSIONS_ALLOWED_ENV_VARS
  • Value: BROWSERLESS_TOKEN

Once this is set and the container is restarted, your expression will work perfectly.

Set N8N_BLOCK_ENV_ACCESS_IN_NODE=false in your docker/k8s env and restart, that’ll let $env work in expression fields. One gotcha though — the editor preview will still show “access denied” even when it’s configured correctly, the values only resolve during actual execution so don’t let that throw you off.

1 Like

the values only resolve during actual execution so don’t let that throw you off.

why have you forsaken me this way, n8n?

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