Hi,
In my project, each device has several unique properties such as serial_number and owner_id. Every time I setup a new device for my customer, I need to manually set the env vars for the flow by double clicking the flow tab and put the key-value pairs in.
I have a development machine which will push changes and all the devices will only pull from the repo. However, every time I pull the code, the env vars will be overwritten, I have to manually set the vars for each single device.
It has a very bad scalability if there are thousands of devices, it is impossible to manually setup the env vars every time I need to update the code.
What would be the best practice of this?
Thank for helping!
That depends on the OS and how you run node red.
It runs on Ubuntu 20.04, there is a service for node-red named run_node_red
to run node-red.
The Linux Node-red installer supplies a systemd script which can set up environment variables. But you seem to be using some other startup mechanism.
You can specify environment variables in settings.js. it's not difficult to write a script to do this.
In the systemd script you can include a file containing env vars, which you could modify for each system. As @jbudd says the pi/debian/ubuntu install script does this for you. The systemd script includes the line
EnvironmentFile=-/home/colinl/.node-red/environment
so you could do something similar in your script. The -
before the path tells systemd not to error out if the file does not exist.
I will give a try, thanks for helping! @jbudd @Colin