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 use export
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
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"); msg.home=home; return msg;
Predefined Environmental Variables
Version 2.2 included support for predefined environmental variables that allow access to node properties.
Related Tutorials and Resources:
- Using the Node-Red Function Node- Beginners Guide
- Storing Data in Node-Red Variables
- Understanding and Using The Node-Red Message Object