# Is there a way to externalize mongodb connection info

**URL:** <https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012>\
**Category:** General\
**Created:** [1 September 2019 21:41 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012 "2019-09-01T21:41:28Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [27 December 2019 13:32 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/22 "2019-12-27T13:32:18Z")

</div>

> [@lenny1972](#):
>
> Any thoughts???

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')`.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 December 2019 13:35 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/23 "2019-12-27T13:35:54Z")

</div>

Good to know, I just updated my example!

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [27 December 2019 15:21 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/24 "2019-12-27T15:21:16Z")

</div>

You mention you did the following:

> [@lenny1972](#):
>
> - add the following line `env: process.env` within the functionGlobalContext section. Now this section looks like this:  
> `functionGlobalContext: { env:process.env },`

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?

> [@lenny1972](#):
>
> ```javascript
> functionGlobalContext: { 
> // os:require('os'), 
> // jfive:require("johnny-five"), 
> // j5board:require("johnny-five").Board({repl:false}) 
> },
> 
> ```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 December 2019 15:32 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/25 "2019-12-27T15:32:34Z")

</div>

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](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/9) )

---

<div class="post-metadata">

**Author:** ![lenny1972](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lenny1972/32/13210_2.png) [@lenny1972](https://discourse.nodered.org/u/lenny1972)\
**Post date:** [27 December 2019 16:09 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/26 "2019-12-27T16:09:08Z")

</div>

Thanks Nick and everyone, I finally get it working. For my mistake 😪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!!

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [27 December 2019 16:25 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/27 "2019-12-27T16:25:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lenny1972](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lenny1972/32/13210_2.png) [@lenny1972](https://discourse.nodered.org/u/lenny1972)\
**Post date:** [28 December 2019 08:39 UTC](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012/28 "2019-12-28T08:39:16Z")

</div>

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 😫- 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](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:

```auto
[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 😀

[Previous page](https://discourse.nodered.org/t/is-there-a-way-to-externalize-mongodb-connection-info/15012.md?page=1)
