Understanding Node, Flow, Global, and Environment Variables in Node-RED
Guide to Understanding and Managing Node-RED Variables for Efficient Workflows

Node-RED is a low-code programming tool for connecting hardware, APIs, and online services. While its visual interface makes development accessible, understanding how to work with variables like node, flow, global, and environment is key to building efficient, organized flows.
This guide provides a clear explanation of each variable type in Node-RED, including how to initialize, access, and manage them effectively. Whether you are just starting with Node-RED or looking to improve your workflows, this article will help you gain a solid understanding of the variable context system and how to use it to your advantage.
Understanding Node-RED Variables
Variables help you store and manage data in Node-RED. There are three main types: message, context, and environment variables.
Message variables are part of the message as it moves through the flow. For example, msg.payload
carries the main data between nodes. You can learn more about messages in the Understanding Node-RED Messages guide.
Context variables let you store information about the current state of the application. These can be saved at the node level, the flow level, or globally across the whole instance.
Environment variables are used for configuration and often store sensitive data like secrets or API keys. They help keep important information safe and separate from the flow itself.
Exploring Global variables
Global variables in Node-RED are accessible to function, change, inject, and switch nodes within a given Node-RED instance. They serve as a centralized storage point for data that needs to be accessed across different parts of an application. This is especially useful when you want to share data across multiple flows or tabs within the same Node-RED instance.
For example, in a home automation system with flows for lighting, security, and climate control, global variables can store user preferences or system settings that all flows can access and update. This allows for consistent behavior across the entire system.
Initiating/setting Global variable
We can set Global variables using the function and change node.
In the change node, you can set it as shown in the below image
To initiate a global variable using the function node, use the global's set
method as shown below:
global.set('variableName', value);
Retrieving Global variable
Retrieving global variables using change, inject, and switch nodes is quite similar. You simply need to select the "global" option and enter the variable name in the input field. Below is an image showing how you can retrieve global variables using the change node:
To retrieve a global variable using the function, use the global's get
method like the below in the function node:
global.get('variableName');
Deleting Global variables
To delete the global variables again you can use both the "context data" tab and the change node. I have shown in the below image how you can delete global variables using the change node:
Exploring Flow variables
Flow variables are accessible to function, change, inject, and switch nodes and some third-party nodes within the same tab or flow where they have been set. It is useful for sharing data within a specific flow or tab, allowing for seamless data transfer between nodes within the same flow.
For example, in a temperature monitoring system, you have multiple sensors sending data to different nodes within the same flow. You can use flow variables to pass the current temperature reading between nodes for processing and analysis within that specific flow.
Initiating/Setting Flow variable
We can set flow variables using function and change node.
In the change node, you can set it as shown in the below image
To initiate a flow variable using the function node, use the flow's set
method as shown below:
flow.set('variableName', value);
Retrieving Flow variable
You can retrieve flow variables using the function, change, inject, and switch.
Retrieving flow variables using change, inject, and switch nodes is quite similar. You simply need to select the "flow" option and enter the variable name in the input field. Below is an image showing how you can retrieve flow variables using the change node.
To retrieve a flow variable, use the flow's get
method like the below in the function node:
flow.get('variableName');
Deleting Flow variables
To delete flow variables you can use both the "context data" tab and the change node. I have shown in the below image how you can delete flow variables using the change node:
Exploring Node variables
Node variables are specific to each node and are only visible within that node. This means we cannot read or write into that variable from outside of the node where it is initialized. This is ideal for cases where you want to store data specific to a single node, to ensure data isolation and prevent interference with other nodes
For example, You have a form on a Node-RED Dashboard 2.0, and you want to insert the submitted data into a database along with a unique ID for each submission. You can use a node variable to store and track a counter variable in the function node.
Initiating/setting Node variable
To initiate and set a node variable using the function node, you will have to use the context’s set
method:
context.set('variableName', value);
This action sets the value for the context variable with the specified name.
Retrieving Node variable
To retrieve a node variable using a function node, use the context's get
method:
context.get('variableName');
Deleting Node variables
Node variables cannot be deleted using a Node-RED node. To delete them, use the Context Data tab in the Node-RED editor, where a delete option is available for each variable. For more details, refer to the Exploring the Context Data tab section of this guide.
FlowFuse persistent storage
So far, we have seen three types of context variables and all are stored in memory. This means that when we stop the Node-RED instance, the variables will get wiped out.
FlowFuse provides a way to persist these variable values between restarts and FlowFuse stack updates. For more details, refer to FlowFuse Persistent Context.
Setting Persistent Variables in Function Node
To set variables in persistent store using change node steps are the same as storing them in memory you just need to change the store option to persistent from memory in the change node like below:
In the function node, you just need to pass one more argument "persistent" in the set method.
global.set('variableName',value,'persistent');
flow.set('variableName',value,'persistent');
context.set('variableName',value,'persistent');
Retrieving Persistent Variables
You can retrieve variables stored in the persistent store using the change node as shown in the below image:
To retrieve a variable stored in the persistent store using the function node, you'll need to pass "persistent" in the get method.
global.get('variableName','persistent');
flow.get('variableName','persistent');
context.get('variableName','persistent');
Exploring Context Data tab
Node-RED provides a dedicated interface for viewing and managing all Node-RED variables. Navigate to the sidebar's "Context Data" tab, where you'll find sections for Node, Flow, and Global variables. Each section has a refresh icon at the top right corner; click on it to see the latest or newly added variables.
In this tab, you'll also find information about when each variable was set or updated, along with additional options on the right side of each variable. The first option allows you to copy the variable's name, the second option lets you copy the variable's value, the third option refreshes the variable to show the most recent value, and the fourth option allows you to delete the variable.
Exploring Environmental variables
Environment variables are specifically used for storing sensitive configuration data, such as API keys or database credentials, ensuring this information isn't directly exposed within your flows. In Node-RED you can set environment variables at flow and global level.
-
Flow-level environment: Used to store sensitive configuration data accessible only within a specific flow. This ensures secure and isolated storage of sensitive information. For example, when building a multi-flow Node-RED application, each flow may need different configuration details, like API keys or unique identifiers. Using flow-level environment variables allows each flow to securely store its specific sensitive data without exposing it to other flows.
-
Global-level environment: Variables are used to store sensitive data accessible across all flows in a Node-RED instance. They are helpful when you need to share the same sensitive data across different flows. For example, If multiple flows need to use the same API key, setting a global-level environment variable allows them to access this data securely, avoiding repeated configurations and ensuring consistency.
Setting Environment Variables
To set flow-level environment variables you'll have to use the edit dialog of the flow.
For information on setting and managing global-level environment variables, refer to Using Environment variables in Node-RED.
Accessing Environment variables
Environment variables in the change, inject, and switch nodes can be accessed by selecting the "$ env variable" option and entering the variable name in the input field. Here's an example of Accessing an environment variable using the change node:
To access environment variables in a function node, use:
env.get('variableName');
In the template node, you can access it as shown below:
This is my username : {{env.USERNAME}}.
And if you need to access environment variables in third-party configuration nodes where they haven't provided an option to use environment variables, you can access them with ${variableName}
in the node's input field.
Note: If a flow-level and a global-level environment variable share the same name, Node-RED prioritizes the flow-level variable. To access the global-level variable in this case, prefix the variable name with $parent
.
Deleting Environment variables
To delete added environment variables, you can use the same interface where added them. In the right corner of your added environment variable, you'll see a delete or cross icon. Simply click on it to delete the variable and restart your Node-RED instance.
By now, you should have a complete understanding of how variables function within Node-RED, how to set, retrieve, and delete them, both in memory and in persistent storage.
Conclusion
Building with Node-RED becomes much easier when you understand how data moves and is stored throughout your flows. With the right use of context and configuration, your flows become not just functional, but maintainable and scalable.
As your projects grow, so does the need for better tools—whether it's managing deployments, collaborating with a team, or keeping things running smoothly across environments. That’s where FlowFuse helps you take the next step.
Start using FlowFuse today and improve your Node-RED experience with built-in tools for scaling, collaboration, and reliability
About the Author
Sumit Shinde
Technical Writer
Sumit is a Technical Writer at FlowFuse who helps engineers adopt Node-RED for industrial automation projects. He has authored over 100 articles covering industrial protocols (OPC UA, MQTT, Modbus), Unified Namespace architectures, and practical manufacturing solutions. Through his writing, he makes complex industrial concepts accessible, helping teams connect legacy equipment, build real-time dashboards, and implement Industry 4.0 strategies.
Related Articles:
- Curated Node-RED Integrations: FlowFuse Certified Nodes 2.0
- Announcing Node-RED Con 2025: A Community Conference on Industrial Applications
- Monitoring Device Health and Performance at Scale with FlowFuse
- Interacting with Arduino using Node-RED
- Announcing Node-RED Academy!