I’m searching a way to define variables that could vary through environments (dev, staging, prod°, …)
I don’t know how to do this, and didn’t see anything in the documentation or in the forum.
Maybe I’m not searching with the good words, but, is there a way to do this ?
My need would be to define a base URL, on my PC would be a “192.168.xx.xx”, but on a server, could be in a docker stack, so that could be a string like “api-server”.
This need could be extended to other variables, like paths or files to write, …
I am using docker and there are only Function and FunctionItem nodes can use $env.my_var, other nodes only can access {{$env.NODE_ENV}}.
Please see the image below.
Hi @RicardoE105,
I found it is only the frontend problem. Actually, It can work properly in backend.
Execute Command node front-end showing [not found]:
Yes, that is correct. It will only display them correctly if you execute the node. To make it also work without executing the node, we have to always send all environment variables to the UI which we want to avoid.
Maybe a silly question but is it possible to define an environment variable during the workflow?
Also, is it possible to update it without restarting n8n or reloading the workflow (example: store an access token as an environment variable and refresh it)?
Hello again, I haven’t found a way to set the environment variables during a workflow run. I have tried execute command, function node and the regular set node and sadly none of them achieve it right as far as I can tell.
I stumbled on this today, just wondering if it could be used in parallel to set the environment variables via the workflow?
OK wow, it does! But…How is this possible? What data structure is this? “typeof” says it’s a function, so how is it possible that we can access it with square brackets?
I am not actually show how $env works internally but it looks like you can’t dump all of them easily, At some point I really should dig into the expressions.