Using Environmental Variables

Environmental variables are used on operating systems (Linux,Windows etc) to store user and system data.

Environmental variables are stored as key value pairs of the form name=value.

A common environmental variable on Linux and Windows is the use home directory.

On windows this is HOMEPATH and on Linux HOME.

To view the contents you use the echo command as show below:


echo %HOMEPATH% and echo $HOME

On Linux environmental variables are case sensitive.

All systems allow you to create your own environmental variables.

on Linux you  use export

export test=myvariable

more details for linux are here

Details for window are here

The set command can also be used on both Windows an Linux to view all environmental variables.


Important Note: You cannot set environmental variables in a flow.

Using  Environmental Variables in Node-Red

Environmental variables are available in many nodes like the inject node (shown below) and change node (shown  below)



They can also be used in function nodes using env.get as shown in the sample code below:

let home=env.get("HOME");
return msg;


Predefined Environmental Variables

Version 2.2 included support for predefined environmental variables that allow access to node properties.


Flow and Group Environmental Variables

These are actually part of the node-red environment and not the operating system. They are easier to set up and use.

To set up flow environmental variables.

  • Step 1- Click in the flow tab
  • Step2 – Click on the environmental variable icon
  • Step 3 – Click on the add button to add a new variable


To set up group environmental variables you will first need to create a group of nodes.

If you are unfamiliar with groups then take a look at this grouping nodes video

  • Step 1- Click in the group to highlight it.
  • Step2 – Double click on the group to open its settings and Click on the environmental variable icon
  • Step 3 – Click on the add button to add a new variable


Global Enviromental Variables

Available in v3.1. These are configured in the settings menu.


System and user environmental variables can be used inside node-red and in addition node-red lets you set node-red specific environmental variables for use inside node-red.

Environmental variables are often used for flow initialisation.

Related Tutorials and Resources:

Click to rate this post!
[Total: 3 Average: 5]


  1. Is there any possibility to set env variables from within node-red?
    Same as you can set context variables, something like this:
    let home=env.set(“HOME”,”abc”);

    Would be helpfull If env variables could be overwritten by an envSettings file read by node-red.

Leave a Reply

Your email address will not be published. Required fields are marked *