Reading user environment variables


I'm trying to configure an environment variable by adding the following line in my user's .bashrc file:

export apikey=##############

I am able to see the key in both the terminal and by starting a node shell and typing "process.env.apikey". Still I'm not able to see my variable by using the methods described here:

I am however able to view the HOME variable and it gives me the home directory for the user I expect. What am I missing?

I'm using node v10.24.0, Node-RED v1.3.3 on a raspberry pi 4
I've also confirmed that the nodered process is running as the expected user by checking it in htop


How are you starting node-red? Are you running it directly from a terminal or as a systemd script, for example. If you run it using systemd then the user is not logged in so .bashrc is not run.

If you installed with the recommended script and are using node-red-start to run it (or have it enabled to run on boot) then the environment variable can be set in the systemd script /etc/systemd/system/nodered.service.d so you could set it there. However the problem with that is that it may get overwritten by a node red update so instead you should use sudo systemctl edit nodered which will make an override file where you can add the environment line

Ah, that's it, I'm using systemd and have it enabled to run on boot. Your reply closes the gap in my knowledge, thank you very much!

1 Like

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