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:

environmental-variables-1

echo %HOMEPATH% and echo $HOME

On Linux environmental variables are case sensitive.

All systems allow you to create your own environmental variables.

on Linux 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.

e-v-set

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

Using  Environmental Variables

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

environmental-variable-inject

environmental-variable-change

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

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

ev-function

Predefined Environmental Variables

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

predefined-node-red-environmental-variables

Related Tutorials and Resources:

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

Leave a Reply

Your email address will not be published.