In a previous lecture.
In this course you've learnt about how to create a group that contains multiple notes and the benefits
of doing that.
In this lecture, I'm going to show you a new feature that appeared with no trait version 2.0 that allows
you to set environment variables inside a group.
And once you do that, then those variables will be accessible from any node within this group.
So I've got an extension of the original example that you've seen previously, and in this example I've
got a group already created that contains several debug notes and a change note here.
And before we have a look inside those notes list, check out the group itself, the double click to
open up the properties window.
And then in the environment variables tab can see here that I've got three environmental variables set
for the group itself.
The first one group in VAR one just sets this variable into a fixed string.
So there's a few options here of things that you can store in set environment of.
Our boy just took a string and typed in a bit of text.
The other two are more interesting here because what they do is that they grab a variable and actually
I just found a mistake.
That should be silly.
They just grab a variable that I have already said as an environment variable in this settings file.
So let's switch over to the command line now and have a look at the settings file and just going to
use the cap command for that.
Just need to have a look at the very top of this file.
So at the beginning of this file, outside of the existing module export segment, I have created another
export module to export segment.
And in it I've set a couple of variables.
So each line contains the name for the variable followed by a colon.
Then the words process dot, EMV followed by dot, and then the name of the variable in capitals.
This is a name that I'm using inside node red to access the value for this particular variable.
Let's go back into the file, the settings file and I've got the equals sign and then I'm making a reference
to the operating system function hostname which will return the hostname for my Raspberry Pi.
So this is just one environmental variable that just grabs a piece of information from the operating
system of a comma because then in the next line of code, the second environment variable in this case
it's say a city.
It's just the name that I chose, followed by the colon process that EMV.
And then in capital letters, the name of the environment variable that I'm going to reference from
inside my node, the red node and after the equals sign, just a arbitrary string.
In this case Sydney, which is my city.
So save the updated settings to file and then restart the node red instance like this.
And then the instance at the runtime of the node, for instance, a will pick up this environment variables
and they will be accessible from inside your nodes like this.
So I've got a reference to hostname and city and those are stored in group EMV via two and three respectively.
In my debug notes.
Let's pick up an example and have a look at this one here.
For example, this is just presenting or printing out the value stored in group B in v var three of
the message object.
I've got the same thing here.
So just to recap, before I run this example, you know, trigger it in my group level, I can create
environment variables such as this one here, simply a string or grab values from the operating system,
environmental variables or arbitrary environmental variables that I have set inside the settings file.
All right.
Also, let's check out what's happening in the inject note.
I haven't made any changes compared to what I had in the original example.
I just serve the payload topic which is empty.
And then the message.
Example message here with a bit of text in it.
So I'm going to deploy this flow and then trigger it.
And then you can see that the environment variables that came from the settings file city and hostname
are printed out by the debug nodes as they were set inside the change node.
So just to recap, you can use environment variables in the group level to share the data among all
nodes that are included in the group.
And those environmental variables can be fixed at the group level or the can be fetched or read from
the settings file.
If you want to learn more about environment variables, then have a look at this documentation page.
You can see the URL for this page on your screen right now.