Accessing environmental variables within code in Function nodes

1,161 views
Skip to first unread message

Robert

unread,
Dec 15, 2017, 10:42:01 AM12/15/17
to Node-RED
Hi,

It's possible to inject environmental variables into node configuration text fields using $(ENV_VAR).

Is it possible to do something similar and access environmental variables in code defined within a Function node?

Regards,
Robert

Nick O'Leary

unread,
Dec 15, 2017, 11:07:19 AM12/15/17
to Node-RED Mailing List
Hi Robert,

not by default.

If you configure your functionGlobalContext in your settings file, you can expose them...

   functionGlobalContext: {
      env: process.env
   }

Then, in your Function:

   var env = global.get('env');
   // Use env.ENV_VAR


Regards,
Nick



--
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+unsubscribe@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/4929769d-17ee-4c5c-b92d-c85acbb7c53f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zenofmud

unread,
Dec 15, 2017, 11:30:48 AM12/15/17
to node...@googlegroups.com
You might want to look at the flow and writeup I put up two weeks ago:
Using environmental variables (system or user defined)
Here’s the link: https://flows.nodered.org/flow/8a13d11dfe80e279df83341e3e17bcc1
-Paul
> --
> 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.

David Caparrós

unread,
Dec 15, 2017, 11:33:56 AM12/15/17
to Node-RED
Hi Paul, link is not working

Nick O'Leary

unread,
Dec 15, 2017, 11:37:57 AM12/15/17
to Node-RED Mailing List

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Colin Law

unread,
Dec 15, 2017, 11:38:28 AM12/15/17
to node...@googlegroups.com
Take the -Paul off the end of the link after pasting into browser.

Colin

On 15 December 2017 at 16:33, David Caparrós <davi...@gmail.com> wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@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,
Dec 15, 2017, 11:54:17 AM12/15/17
to node...@googlegroups.com
Oops, I guess I forgot to hit return and just typed that in on what AI thought was the next line (:<(

Robert

unread,
Dec 18, 2017, 7:00:08 AM12/18/17
to Node-RED
@Nick
"env: process.env" did the trick - thanks!

@Paul
Might be a small typo in your linked document - "env:require(env)" didn't work for me.

Regards,
Robert

Zenofmud

unread,
Dec 18, 2017, 8:49:32 AM12/18/17
to node...@googlegroups.com
Oops, yup a copy/paste error, it should be "env: process.env” NOT "env:require(env)”. I’ll go fix that in the write up. Thanks for spotting that.
Reply all
Reply to author
Forward
0 new messages