Is there a way to externalize mongodb connection info

  1. Make sure there are no spaces around the ${...}
  2. Make sure you've edited the right settings file - NR logs the file it uses on start up.
  3. Make sure you have restarted NR after editing the right settings file.
  4. Try accessing the value in a function node using env.get('TEST').

Good to know, I just updated my example!

You mention you did the following:

But in the full settings file you posted it doesn't show up there. Can you verify that you did indeed add it to the global context?

As pointed out by @knolleary - you no longer need to add it to globalContext manually - it is there by default. ( Back in post 9 - Is there a way to externalize mongodb connection info )

Thanks Nick and everyone, I finally get it working. For my mistake :sleepy:I didn't modify the real settings.js config file. In fact I modified the settings.js file placed in the the /home/pi/.node-red/ directory and not that present within the /root/.node-red/ one that is the one used by NR when it starts.

Everything's working now!!

Thanks again & have a Good Year's Eve to Everybody!!

Going to come back to this for a bit, but is there a specific reason why you are running Node-RED as root?

HI Lena effectively I had no particular reason for need to run it as a root.
At the beginning I started with the pi user and worked on the flows file that are now in the /home/pi/.node-red directory and after a while - for a mistake :tired_face:- I started working a lot on the flows file that is in the /root/.node-red directory. I've read a lot of articles about avoiding runnign node-red as root and I want to get your suggestion and run it with the pi user (that has admin rights) instead.
Considering that now the right flows file is in the /root/.node.red directory and also all the palette has been installed (via Manage Palette) with the user root what's the best solution for "migrating" from root to pi user?

My question now are:

  • Is it possible to start NodeRed flows that re in the /root/.node.red with the user pi, or do I have to replace the flows file that is in the /home/pi/.node-red directory (the old one that is now outdated) with the good flows file (that it's in the /root/.node.red directory) and reinstall all the palettes I may need?
  • Or is it possigle to tell Node-Red to start from the /root/.node.red directory (su using the good flows file) but start with the pi user (that should be the best option I suppose)?

Now at the Raspi boot the Node-Red flows that is started is the good ones (but is started as root). I've followed this instruction https://nodered.org/docs/faq/starting-node-red-on-boot and so Node-Red has been installed as a systemd service. I've checked the node-red.service configuration file in /lib/systemd/system/ and the service is configured as follows:

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=root
Group=root
WorkingDirectory=/root

Do you think that by only changing the User and Group attributes from root to pi but leaving the WorkingDirectory to /root because the good flows and palette are in that directory (and logically giving access to the \root\.node-red directory to the user pi) in this service configuration file will enable me to run NodeRed with the pi user without problems?

Any help will be greatly appreciated :grinning: