Setting config node attribs from flow?

322 views
Skip to first unread message

Torsten Schmale

unread,
Feb 25, 2018, 2:07:45 PM2/25/18
to Node-RED
Hi,

I am looking for a way to overwrite config node attribs from within a flow.

Why?
Because I have the mongodb parameters in the settings.js and I now need to set/overwrite the mongodb config attribs on NR startup

thanks in advance
Torsten

Julian Knight

unread,
Feb 26, 2018, 5:07:47 PM2/26/18
to Node-RED
If you only need something at startup, then setting in settings.js is best. Either as an environment variable or a global depending on need. Many (all?) nodes can consume an environment variable in a setting by using "{env-var-name}".

Dave C-J

unread,
Feb 26, 2018, 5:50:06 PM2/26/18
to node...@googlegroups.com
To use an environment variable in a node's config you need $(env-var-name) syntax.

Zenofmud

unread,
Feb 26, 2018, 6:56:13 PM2/26/18
to node...@googlegroups.com
For environment variables, here is a writeup I did a couple months ago: https://flows.nodered.org/flow/8a13d11dfe80e279df83341e3e17bcc1

On Feb 26, 2018, at 5:50 PM, Dave C-J <dce...@gmail.com> wrote:

To use an environment variable in a node's config you need $(env-var-name) syntax.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/CACXWFwJ0uiNeiAeB4iJwPdos3w6j-mMWNnULvrhbWVsgh-ecFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Torsten Schmale

unread,
Feb 26, 2018, 7:00:14 PM2/26/18
to Node-RED
yes, using setting.js is good and the docs tell me how to read these values in a function node.
but the docs don't tell anything about how one can set/overwrite the attributes of a config node.

in other words:
some nodes like mongodb or mqtt do work with central config nodes for host, port, user etc. 
its easy to set them via node-red admin UI but I want to set/overwrite them either on node-red startup or at runtime from within a flow (with my ones I have added to settings.js in the functionGlobalContext

I am wondering that this is not a well known pattern in node-red. Separation of productive credentials from code (or here flows) is always a good idea and necessary if you develop in one environment and then deploy it to a productive environement.

Torsten Schmale

unread,
Feb 26, 2018, 7:21:45 PM2/26/18
to Node-RED
Thanks Paul. I have tried that but it does not work (or I understand your writeup wrong):

I have added your statement but on node-start it says: Error: Cannot find module 'env'



I have also tried without and used $(harry) for the database name in the mongodb config node
there it says - "MongoError: database names cannot contain the character '$'"

Zenofmud

unread,
Feb 26, 2018, 8:47:12 PM2/26/18
to node...@googlegroups.com
I’ll review it tomorrow morning (east coast USA)

Sent from my iPad
--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Zenofmud

unread,
Feb 27, 2018, 6:11:59 AM2/27/18
to hrokade via Node-RED
Blast, I forgot to correct that (sigh) instead of 
env:require(‘env’)
it should be:
       env: process(‘env’)
and make sure the single quotes are the tick marks not the fancy single quotes.

(off to fix the git)
Paul

Zenofmud

unread,
Feb 27, 2018, 6:23:54 AM2/27/18
to node...@googlegroups.com
(turns out I had fixed it in GitHub gist, but I had made it a secret gist (oops). It should flow over to the node red flows soon but you can go to the GitHub link to see the change.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Torsten Schmale

unread,
Feb 27, 2018, 10:34:29 AM2/27/18
to Node-RED
Thanks Paul, Dave and Julian. I finally got what I want - its working now.

The only remaining restriction is, that the $(env-var-name) does read from env only, i.e. there is no fallback || ... in setting.js possible 
as it is works from within a function node e.g. msg.payload.dbname = global.get('DBNAME');

Finally, my relevant settings.js part and how it looks then in a mongodb config node:


Reply all
Reply to author
Forward
0 new messages