Production Vs Dev environment config

Hi
I'm about to use node-red as part of server/service monitoring project. I'm developing on my local machine and have http endpoints and mqtt server configurations (TLS certificates) etc all pointing to local/test data. How can I save my configuration nodes somewhere else (not in the flow.json) so I can specify a different set for the production environment? Or alternatively populate required fields from the values stored in settings.js?

It all depends on the node. Some support environment variables. For example, node-red-contrib-mssql-plus permits you to use environment variables for the connection fields. Some nodes don't. Other nodes might permit you to inject values in the msg (meaning you can load from file or env if need be and pass them to the node at runtime)

I'd suggest you try to put as much as possible into environment vars - see how far you get. When you get stuck, ask a question about a specific node. Perhaps there is an answer or the Dev could modify the node to use env vars.

PS I believe you can also set environment variables in the settings.js (search the forum)

Also, don't forget that you have a number of ways to set env. variables when working with Node-RED.

If you are starting NR from systemd for example, you can specify a file to load env variables during startup, I do that with my installations with the file being kept in the userDir folder though you could put it anywhere.

Otherwise, you could do something very similar just with NR's settings.js file. Since that is executed at startup and is run under node.js, you can read a file to apply as env variables very easily.

I also pass the env variables at NR runtime as a global variable. At least for my dev system. That way, I can easily see what they are without having to mess around.

Thanks for all the info. In my case it is the MQTT broker and MQTT TLS. I don't see that it supports env variables. But I also realized that the flow file is just JSON so I can easily write a script in one of the 'build steps' to modify what I want for production.

Hi.

Did you try?

Perhaps you could raise a feature request in the core development > feature requests category.

Lastly, I believe credentials for that node are not in the flow file but encrypted in a separate file adjacent.

1 Like

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