[{"data":1,"prerenderedAt":1397},["ShallowReactive",2],{"blog-\u002Fblog\u002F2024\u002F05\u002Funderstanding-node-flow-global-environment-variables-in-node-red":3,"blog-all-for-related":1396},{"id":4,"title":5,"authors":6,"body":8,"cta":1317,"date":1321,"description":1322,"extension":1323,"image":1324,"lastUpdated":1325,"meta":1326,"navigation":1383,"path":1384,"seo":1385,"sitemap":1386,"stem":1387,"subtitle":1388,"tags":1389,"tldr":1393,"video":1394,"__hash__":1395},"blog\u002Fblog\u002F2024\u002F05\u002Funderstanding-node-flow-global-environment-variables-in-node-red.md","How to Use Variables in Node-RED: Flow, Global, Context & Environment (2026)",[7],"sumit-shinde",{"type":9,"value":10,"toc":1295},"minimark",[11,67,70,75,78,81,97,103,109,113,116,122,127,133,136,149,158,161,245,251,254,261,264,328,334,341,345,348,354,358,363,366,373,375,433,438,441,448,450,510,516,523,527,530,536,540,543,548,610,615,680,686,690,693,696,700,705,708,713,716,824,829,832,839,841,951,954,958,961,968,973,991,994,1001,1005,1008,1011,1017,1023,1027,1032,1046,1053,1061,1066,1069,1076,1078,1140,1143,1174,1181,1191,1197,1201,1204,1209,1223,1239,1245,1251,1257,1263,1267,1285,1288,1291],[12,13,14,15,19,20,24,25,28,29,32,33,36,37,40,41,44,45,48,49,52,53,48,56,59,60,48,63,66],"p",{},"Node-RED has four types of variables: ",[16,17,18],"strong",{},"message variables"," that travel with ",[21,22,23],"code",{},"msg"," through your nodes, and ",[16,26,27],{},"context variables"," in three scopes, ",[16,30,31],{},"node"," (private to a single function node), ",[16,34,35],{},"flow"," (shared within one tab), and ",[16,38,39],{},"global"," (shared across the entire instance), plus ",[16,42,43],{},"environment variables"," for configuration and secrets. You set and retrieve context variables with ",[21,46,47],{},"global.set()","\u002F",[21,50,51],{},"global.get()",", ",[21,54,55],{},"flow.set()",[21,57,58],{},"flow.get()",", and ",[21,61,62],{},"context.set()",[21,64,65],{},"context.get()"," in function nodes, or visually through the change node. Context variables are stored in memory by default and are lost on restart, so any state that must survive a reboot needs persistent storage.",[12,68,69],{},"That's the short version. The rest of this guide walks through each variable type in detail, showing you exactly how to set, retrieve, and delete them, when to use each scope, and how to make them persist across restarts and redeployments.",[71,72,74],"h2",{"id":73},"what-are-node-red-variables","What Are Node-RED Variables?",[12,76,77],{},"Variables in Node-RED serve as containers for storing and managing data throughout your application. Understanding the different types and their scopes is essential for building efficient, organized flows.",[12,79,80],{},"Node-RED offers three primary variable categories:",[12,82,83,86,87,90,91,96],{},[16,84,85],{},"Message variables"," travel with the message object as it flows through your nodes. The most common example is ",[21,88,89],{},"msg.payload",", which carries the primary data between nodes. For a deeper dive into message handling, see the ",[92,93,95],"a",{"href":94},"\u002Fnode-red\u002Fgetting-started\u002Fnode-red-messages\u002F","Understanding Node-RED Messages"," guide.",[12,98,99,102],{},[16,100,101],{},"Context variables"," store application state at different levels, node, flow, or global scope. They persist data that needs to be accessed across multiple message events, making them ideal for tracking counters, storing configuration, or maintaining state.",[12,104,105,108],{},[16,106,107],{},"Environment variables"," handle configuration data and sensitive information like API keys and credentials. By storing this data separately from your flows, you maintain security and make configuration management more flexible.",[71,110,112],{"id":111},"global-variables-instance-wide-data-storage","Global Variables: Instance-Wide Data Storage",[12,114,115],{},"Global variables provide a centralized storage mechanism accessible throughout your entire Node-RED instance. Any function, change, inject, or switch node can read or write global variables, making them perfect for sharing data across multiple flows.",[12,117,118,121],{},[16,119,120],{},"When to use global variables:"," Consider using them for system-wide settings, shared configuration, or data that multiple flows need to access. For example, in a home automation system with separate flows for lighting, security, and climate control, global variables can store user preferences that all flows reference.",[123,124,126],"h3",{"id":125},"working-with-global-variables","Working with Global Variables",[12,128,129,132],{},[16,130,131],{},"Setting global variables"," can be done through the change node or programmatically in a function node:",[12,134,135],{},"Using the change node:",[137,138,139,143,146],"ol",{},[140,141,142],"li",{},"Select \"global\" from the variable type dropdown",[140,144,145],{},"Enter your variable name",[140,147,148],{},"Set the value or expression",[12,150,151],{},[152,153],"img",{"alt":154,"dataZoomable":155,"src":156,"title":157},"\"Screenshot showing how to set global variable using the change node\"","","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-setting-global-variable-using-change-node.png","Screenshot showing how to set global variable using the change node",[12,159,160],{},"Using a function node:",[162,163,167],"pre",{"className":164,"code":165,"language":166,"meta":155,"style":155},"language-javascript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","global.set('userName', 'John');\nglobal.set('systemMode', 'active');\n","javascript",[21,168,169,214],{"__ignoreMap":155},[170,171,174,177,181,185,188,191,195,197,200,203,206,208,211],"span",{"class":172,"line":173},"line",1,[170,175,39],{"class":176},"sTEyZ",[170,178,180],{"class":179},"sMK4o",".",[170,182,184],{"class":183},"s2Zo4","set",[170,186,187],{"class":176},"(",[170,189,190],{"class":179},"'",[170,192,194],{"class":193},"sfazB","userName",[170,196,190],{"class":179},[170,198,199],{"class":179},",",[170,201,202],{"class":179}," '",[170,204,205],{"class":193},"John",[170,207,190],{"class":179},[170,209,210],{"class":176},")",[170,212,213],{"class":179},";\n",[170,215,217,219,221,223,225,227,230,232,234,236,239,241,243],{"class":172,"line":216},2,[170,218,39],{"class":176},[170,220,180],{"class":179},[170,222,184],{"class":183},[170,224,187],{"class":176},[170,226,190],{"class":179},[170,228,229],{"class":193},"systemMode",[170,231,190],{"class":179},[170,233,199],{"class":179},[170,235,202],{"class":179},[170,237,238],{"class":193},"active",[170,240,190],{"class":179},[170,242,210],{"class":176},[170,244,213],{"class":179},[12,246,247,250],{},[16,248,249],{},"Retrieving global variables"," follows a similar pattern:",[12,252,253],{},"In a change, inject, or switch node, simply set the action to “set”, choose the type as “global”, and specify the variable name.",[12,255,256],{},[152,257],{"alt":258,"dataZoomable":155,"src":259,"title":260},"\"Screenshot showing how to retrieve global variables using the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-retrieving-global-variable-using-change-node.png","Screenshot showing how to retrieve global variables using the change node",[12,262,263],{},"In function nodes:",[162,265,267],{"className":164,"code":266,"language":166,"meta":155,"style":155},"const userName = global.get('userName');\nconst mode = global.get('systemMode');\n",[21,268,269,301],{"__ignoreMap":155},[170,270,271,275,278,281,284,286,289,291,293,295,297,299],{"class":172,"line":173},[170,272,274],{"class":273},"spNyl","const",[170,276,277],{"class":176}," userName ",[170,279,280],{"class":179},"=",[170,282,283],{"class":176}," global",[170,285,180],{"class":179},[170,287,288],{"class":183},"get",[170,290,187],{"class":176},[170,292,190],{"class":179},[170,294,194],{"class":193},[170,296,190],{"class":179},[170,298,210],{"class":176},[170,300,213],{"class":179},[170,302,303,305,308,310,312,314,316,318,320,322,324,326],{"class":172,"line":216},[170,304,274],{"class":273},[170,306,307],{"class":176}," mode ",[170,309,280],{"class":179},[170,311,283],{"class":176},[170,313,180],{"class":179},[170,315,288],{"class":183},[170,317,187],{"class":176},[170,319,190],{"class":179},[170,321,229],{"class":193},[170,323,190],{"class":179},[170,325,210],{"class":176},[170,327,213],{"class":179},[12,329,330,333],{},[16,331,332],{},"Deleting global variables"," can be accomplished through the change node by selecting \"delete\" from the action dropdown, or via the Context Data sidebar panel, which provides a comprehensive view of all variables.",[12,335,336],{},[152,337],{"alt":338,"dataZoomable":155,"src":339,"title":340},"\"Screenshot showing how to delete global variable using the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-deleting-global-variable-using-change-node.png","Screenshot showing how to delete global variable using the change node",[71,342,344],{"id":343},"flow-variables-tab-scoped-data","Flow Variables: Tab-Scoped Data",[12,346,347],{},"Flow variables exist within a single tab or flow in your Node-RED editor. They're accessible to all nodes within that specific flow but isolated from other flows, providing logical data separation.",[12,349,350,353],{},[16,351,352],{},"When to use flow variables:"," Use them for data that's relevant only to a specific workflow. For instance, in a temperature monitoring flow with multiple sensor nodes, flow variables can track the current reading, alert thresholds, or calculation results, data that doesn't need to be shared with other parts of your application.",[123,355,357],{"id":356},"working-with-flow-variables","Working with Flow Variables",[12,359,360],{},[16,361,362],{},"Setting flow variables:",[12,364,365],{},"Using the change node, select the action “set”, choose “flow” as the variable type, and configure your variable.",[12,367,368],{},[152,369],{"alt":370,"dataZoomable":155,"src":371,"title":372},"\"Screenshot showing how to set flow variable using the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-setting-flow-variable-using-change-node.png","Screenshot showing how to set flow variable using the change node",[12,374,263],{},[162,376,378],{"className":164,"code":377,"language":166,"meta":155,"style":155},"flow.set('currentTemp', 72.5);\nflow.set('alertThreshold', 85);\n",[21,379,380,407],{"__ignoreMap":155},[170,381,382,384,386,388,390,392,395,397,399,403,405],{"class":172,"line":173},[170,383,35],{"class":176},[170,385,180],{"class":179},[170,387,184],{"class":183},[170,389,187],{"class":176},[170,391,190],{"class":179},[170,393,394],{"class":193},"currentTemp",[170,396,190],{"class":179},[170,398,199],{"class":179},[170,400,402],{"class":401},"sbssI"," 72.5",[170,404,210],{"class":176},[170,406,213],{"class":179},[170,408,409,411,413,415,417,419,422,424,426,429,431],{"class":172,"line":216},[170,410,35],{"class":176},[170,412,180],{"class":179},[170,414,184],{"class":183},[170,416,187],{"class":176},[170,418,190],{"class":179},[170,420,421],{"class":193},"alertThreshold",[170,423,190],{"class":179},[170,425,199],{"class":179},[170,427,428],{"class":401}," 85",[170,430,210],{"class":176},[170,432,213],{"class":179},[12,434,435],{},[16,436,437],{},"Retrieving flow variables:",[12,439,440],{},"In a change, inject, or switch node, simply set the action to “set”, choose the type as “flow”, and specify the variable name.",[12,442,443],{},[152,444],{"alt":445,"dataZoomable":155,"src":446,"title":447},"\"Screenshot showing how to retrieve flow variable using the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-retrieving-flow-variable-using-change-node.png","Screenshot showing how to retrieve flow variable using the change node",[12,449,263],{},[162,451,453],{"className":164,"code":452,"language":166,"meta":155,"style":155},"const temp = flow.get('currentTemp');\nconst threshold = flow.get('alertThreshold');\n",[21,454,455,483],{"__ignoreMap":155},[170,456,457,459,462,464,467,469,471,473,475,477,479,481],{"class":172,"line":173},[170,458,274],{"class":273},[170,460,461],{"class":176}," temp ",[170,463,280],{"class":179},[170,465,466],{"class":176}," flow",[170,468,180],{"class":179},[170,470,288],{"class":183},[170,472,187],{"class":176},[170,474,190],{"class":179},[170,476,394],{"class":193},[170,478,190],{"class":179},[170,480,210],{"class":176},[170,482,213],{"class":179},[170,484,485,487,490,492,494,496,498,500,502,504,506,508],{"class":172,"line":216},[170,486,274],{"class":273},[170,488,489],{"class":176}," threshold ",[170,491,280],{"class":179},[170,493,466],{"class":176},[170,495,180],{"class":179},[170,497,288],{"class":183},[170,499,187],{"class":176},[170,501,190],{"class":179},[170,503,421],{"class":193},[170,505,190],{"class":179},[170,507,210],{"class":176},[170,509,213],{"class":179},[12,511,512,515],{},[16,513,514],{},"Deleting flow variables"," works the same way as global variables, use the change node's delete action or the Context Data panel.",[12,517,518],{},[152,519],{"alt":520,"dataZoomable":155,"src":521,"title":522},"\"Screenshot showing how to delete flow variable using the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-deleting-flow-variable-using-change-node.png","Screenshot showing how to delete flow variable using the change node",[71,524,526],{"id":525},"node-variables-node-level-isolation","Node Variables: Node-Level Isolation",[12,528,529],{},"Node variables (also called node context) are the most restrictive scope, they exist only within a single node. No other node can access or modify these variables, making them ideal for maintaining private state.",[12,531,532,535],{},[16,533,534],{},"When to use node variables:"," Perfect for counters, temporary calculations, or any data that should remain private to a specific node. For example, a function node that generates unique IDs for database records can maintain a counter variable that's never exposed to other parts of your flow.",[123,537,539],{"id":538},"working-with-node-variables","Working with Node Variables",[12,541,542],{},"Node variables are local to a Function node and cannot be read or modified by other nodes.",[12,544,545],{},[16,546,547],{},"Setting node variables:",[162,549,551],{"className":164,"code":550,"language":166,"meta":155,"style":155},"context.set('counter', 0);\ncontext.set('lastProcessedId', 'ABC123');\n",[21,552,553,580],{"__ignoreMap":155},[170,554,555,558,560,562,564,566,569,571,573,576,578],{"class":172,"line":173},[170,556,557],{"class":176},"context",[170,559,180],{"class":179},[170,561,184],{"class":183},[170,563,187],{"class":176},[170,565,190],{"class":179},[170,567,568],{"class":193},"counter",[170,570,190],{"class":179},[170,572,199],{"class":179},[170,574,575],{"class":401}," 0",[170,577,210],{"class":176},[170,579,213],{"class":179},[170,581,582,584,586,588,590,592,595,597,599,601,604,606,608],{"class":172,"line":216},[170,583,557],{"class":176},[170,585,180],{"class":179},[170,587,184],{"class":183},[170,589,187],{"class":176},[170,591,190],{"class":179},[170,593,594],{"class":193},"lastProcessedId",[170,596,190],{"class":179},[170,598,199],{"class":179},[170,600,202],{"class":179},[170,602,603],{"class":193},"ABC123",[170,605,190],{"class":179},[170,607,210],{"class":176},[170,609,213],{"class":179},[12,611,612],{},[16,613,614],{},"Retrieving node variables:",[162,616,618],{"className":164,"code":617,"language":166,"meta":155,"style":155},"let counter = context.get('counter');\ncounter++;\ncontext.set('counter', counter);\n",[21,619,620,649,656],{"__ignoreMap":155},[170,621,622,625,628,630,633,635,637,639,641,643,645,647],{"class":172,"line":173},[170,623,624],{"class":273},"let",[170,626,627],{"class":176}," counter ",[170,629,280],{"class":179},[170,631,632],{"class":176}," context",[170,634,180],{"class":179},[170,636,288],{"class":183},[170,638,187],{"class":176},[170,640,190],{"class":179},[170,642,568],{"class":193},[170,644,190],{"class":179},[170,646,210],{"class":176},[170,648,213],{"class":179},[170,650,651,653],{"class":172,"line":216},[170,652,568],{"class":176},[170,654,655],{"class":179},"++;\n",[170,657,659,661,663,665,667,669,671,673,675,678],{"class":172,"line":658},3,[170,660,557],{"class":176},[170,662,180],{"class":179},[170,664,184],{"class":183},[170,666,187],{"class":176},[170,668,190],{"class":179},[170,670,568],{"class":193},[170,672,190],{"class":179},[170,674,199],{"class":179},[170,676,677],{"class":176}," counter)",[170,679,213],{"class":179},[12,681,682,685],{},[16,683,684],{},"Deleting node variables"," must be done through the Context Data sidebar panel.",[71,687,689],{"id":688},"persistent-storage-with-flowfuse","Persistent Storage with FlowFuse",[12,691,692],{},"By default, all context variables (node, flow, and global) are stored in memory. This means they're lost whenever you restart Node-RED or redeploy your flows. For production applications, this is often unacceptable.",[12,694,695],{},"FlowFuse provides persistent storage that survives restarts, redeployments, and system updates. This ensures your application state remains intact across sessions.",[123,697,699],{"id":698},"using-persistent-storage","Using Persistent Storage",[12,701,702],{},[16,703,704],{},"Setting persistent variables:",[12,706,707],{},"In the change node, select \"persistent\" from the store dropdown instead of \"memory\".",[12,709,710],{},[152,711],{"alt":154,"dataZoomable":155,"src":712,"title":157},"\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-change-node-persistent-store-option-for-while-setting-variable.gif",[12,714,715],{},"In function nodes, add \"persistent\" as a third parameter:",[162,717,719],{"className":164,"code":718,"language":166,"meta":155,"style":155},"global.set('userData', userData, 'persistent');\nflow.set('sessionConfig', config, 'persistent');\ncontext.set('processedCount', count, 'persistent');\n",[21,720,721,756,790],{"__ignoreMap":155},[170,722,723,725,727,729,731,733,736,738,740,743,745,747,750,752,754],{"class":172,"line":173},[170,724,39],{"class":176},[170,726,180],{"class":179},[170,728,184],{"class":183},[170,730,187],{"class":176},[170,732,190],{"class":179},[170,734,735],{"class":193},"userData",[170,737,190],{"class":179},[170,739,199],{"class":179},[170,741,742],{"class":176}," userData",[170,744,199],{"class":179},[170,746,202],{"class":179},[170,748,749],{"class":193},"persistent",[170,751,190],{"class":179},[170,753,210],{"class":176},[170,755,213],{"class":179},[170,757,758,760,762,764,766,768,771,773,775,778,780,782,784,786,788],{"class":172,"line":216},[170,759,35],{"class":176},[170,761,180],{"class":179},[170,763,184],{"class":183},[170,765,187],{"class":176},[170,767,190],{"class":179},[170,769,770],{"class":193},"sessionConfig",[170,772,190],{"class":179},[170,774,199],{"class":179},[170,776,777],{"class":176}," config",[170,779,199],{"class":179},[170,781,202],{"class":179},[170,783,749],{"class":193},[170,785,190],{"class":179},[170,787,210],{"class":176},[170,789,213],{"class":179},[170,791,792,794,796,798,800,802,805,807,809,812,814,816,818,820,822],{"class":172,"line":658},[170,793,557],{"class":176},[170,795,180],{"class":179},[170,797,184],{"class":183},[170,799,187],{"class":176},[170,801,190],{"class":179},[170,803,804],{"class":193},"processedCount",[170,806,190],{"class":179},[170,808,199],{"class":179},[170,810,811],{"class":176}," count",[170,813,199],{"class":179},[170,815,202],{"class":179},[170,817,749],{"class":193},[170,819,190],{"class":179},[170,821,210],{"class":176},[170,823,213],{"class":179},[12,825,826],{},[16,827,828],{},"Retrieving persistent variables:",[12,830,831],{},"In a change, inject, or switch node, ensure you're selecting from the \"persistent\" store.",[12,833,834],{},[152,835],{"alt":836,"dataZoomable":155,"src":837,"title":838},"\"Screenshot showing how to retrieve global variable using the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-change-node-persistent-store-option.gif","Screenshot showing how to retrieve global variable using the change node",[12,840,263],{},[162,842,844],{"className":164,"code":843,"language":166,"meta":155,"style":155},"const userData = global.get('userData', 'persistent');\nconst config = flow.get('sessionConfig', 'persistent');\nconst count = context.get('processedCount', 'persistent');\n",[21,845,846,881,916],{"__ignoreMap":155},[170,847,848,850,853,855,857,859,861,863,865,867,869,871,873,875,877,879],{"class":172,"line":173},[170,849,274],{"class":273},[170,851,852],{"class":176}," userData ",[170,854,280],{"class":179},[170,856,283],{"class":176},[170,858,180],{"class":179},[170,860,288],{"class":183},[170,862,187],{"class":176},[170,864,190],{"class":179},[170,866,735],{"class":193},[170,868,190],{"class":179},[170,870,199],{"class":179},[170,872,202],{"class":179},[170,874,749],{"class":193},[170,876,190],{"class":179},[170,878,210],{"class":176},[170,880,213],{"class":179},[170,882,883,885,888,890,892,894,896,898,900,902,904,906,908,910,912,914],{"class":172,"line":216},[170,884,274],{"class":273},[170,886,887],{"class":176}," config ",[170,889,280],{"class":179},[170,891,466],{"class":176},[170,893,180],{"class":179},[170,895,288],{"class":183},[170,897,187],{"class":176},[170,899,190],{"class":179},[170,901,770],{"class":193},[170,903,190],{"class":179},[170,905,199],{"class":179},[170,907,202],{"class":179},[170,909,749],{"class":193},[170,911,190],{"class":179},[170,913,210],{"class":176},[170,915,213],{"class":179},[170,917,918,920,923,925,927,929,931,933,935,937,939,941,943,945,947,949],{"class":172,"line":658},[170,919,274],{"class":273},[170,921,922],{"class":176}," count ",[170,924,280],{"class":179},[170,926,632],{"class":176},[170,928,180],{"class":179},[170,930,288],{"class":183},[170,932,187],{"class":176},[170,934,190],{"class":179},[170,936,804],{"class":193},[170,938,190],{"class":179},[170,940,199],{"class":179},[170,942,202],{"class":179},[170,944,749],{"class":193},[170,946,190],{"class":179},[170,948,210],{"class":176},[170,950,213],{"class":179},[12,952,953],{},"Persistent storage allows Node-RED to retain state between restarts, crucial for historical metrics, long-running counters, dashboard application data, and any flow that must persist through a reboot without losing information.",[71,955,957],{"id":956},"the-context-data-panel","The Context Data Panel",[12,959,960],{},"Node-RED includes a dedicated Context Data panel in the sidebar that provides visibility into all your variables. This panel is invaluable for debugging and understanding your application's state.",[12,962,963],{},[152,964],{"alt":965,"dataZoomable":155,"src":966,"title":967},"\"Screenshot showing Node-RED Context data tab\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-context-data-tab.png","Screenshot showing Node-RED Context data tab",[12,969,970],{},[16,971,972],{},"Features of the Context Data panel:",[974,975,976,979,982,985,988],"ul",{},[140,977,978],{},"View all node, flow, and global variables in organized sections",[140,980,981],{},"See when each variable was last updated",[140,983,984],{},"Copy variable names or values with one click",[140,986,987],{},"Refresh individual variables to see current values",[140,989,990],{},"Delete variables directly from the interface",[12,992,993],{},"To access this panel, open the sidebar and choose ‘Context Data’ from the dropdown menu. Use the refresh icon in each section to update the display with the latest values.",[12,995,996],{},[152,997],{"alt":998,"dataZoomable":155,"src":999,"title":1000},"\"Screenshot showing Node-RED Context data tab options for managing variables\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-context-data-tab-options-for-varrables.png","Screenshot showing Node-RED Context data tab options for managing variables",[71,1002,1004],{"id":1003},"environment-variables-secure-configuration","Environment Variables: Secure Configuration",[12,1006,1007],{},"Environment variables serve a different purpose than context variables, they're designed for configuration data, especially sensitive information that shouldn't be hardcoded in your flows.",[12,1009,1010],{},"Node-RED supports environment variables at two levels:",[12,1012,1013,1016],{},[16,1014,1015],{},"Flow-level environment variables"," are accessible only within a specific flow. This is useful when different flows need different configurations. For example, one flow might connect to a development database while another connects to production, each using its own credentials.",[12,1018,1019,1022],{},[16,1020,1021],{},"Global-level environment variables"," are accessible across all flows in your instance. Use these for shared configuration like API keys that multiple flows need to reference.",[123,1024,1026],{"id":1025},"working-with-environment-variables","Working with Environment Variables",[12,1028,1029],{},[16,1030,1031],{},"Setting flow-level environment variables:",[137,1033,1034,1037,1040,1043],{},[140,1035,1036],{},"Double-click on the flow tab to open the edit dialog",[140,1038,1039],{},"Navigate to the \"Environment Variables\" section",[140,1041,1042],{},"Add your variables as name-value pairs",[140,1044,1045],{},"Click Done and deploy",[12,1047,1048],{},[152,1049],{"alt":1050,"dataZoomable":155,"src":1051,"title":1052},"\"Screenshot showing how to set flow level environment variables\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-setting-flow-scope-enviroment-variable.gif","Screenshot showing how to set flow level environment variables",[12,1054,1055,1056,1060],{},"For global-level environment variables, see ",[92,1057,1059],{"href":1058},"\u002Fblog\u002F2023\u002F01\u002Fenvironment-variables-in-node-red\u002F","Using Environment Variables in Node-RED"," for detailed instructions.",[12,1062,1063],{},[16,1064,1065],{},"Accessing environment variables:",[12,1067,1068],{},"In change, inject, or switch nodes, select \"env variable\" and specify the name.",[12,1070,1071],{},[152,1072],{"alt":1073,"dataZoomable":155,"src":1074,"title":1075},"\"Screenshot showing how to retrieve environment variable in the change node\"","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Fvariables-in-node-red-retrieving-environment-variable-using-change-node.png","Screenshot showing how to retrieve environment variable in the change node",[12,1077,263],{},[162,1079,1081],{"className":164,"code":1080,"language":166,"meta":155,"style":155},"const apiKey = env.get('API_KEY');\nconst dbHost = env.get('DB_HOST');\n",[21,1082,1083,1112],{"__ignoreMap":155},[170,1084,1085,1087,1090,1092,1095,1097,1099,1101,1103,1106,1108,1110],{"class":172,"line":173},[170,1086,274],{"class":273},[170,1088,1089],{"class":176}," apiKey ",[170,1091,280],{"class":179},[170,1093,1094],{"class":176}," env",[170,1096,180],{"class":179},[170,1098,288],{"class":183},[170,1100,187],{"class":176},[170,1102,190],{"class":179},[170,1104,1105],{"class":193},"API_KEY",[170,1107,190],{"class":179},[170,1109,210],{"class":176},[170,1111,213],{"class":179},[170,1113,1114,1116,1119,1121,1123,1125,1127,1129,1131,1134,1136,1138],{"class":172,"line":216},[170,1115,274],{"class":273},[170,1117,1118],{"class":176}," dbHost ",[170,1120,280],{"class":179},[170,1122,1094],{"class":176},[170,1124,180],{"class":179},[170,1126,288],{"class":183},[170,1128,187],{"class":176},[170,1130,190],{"class":179},[170,1132,1133],{"class":193},"DB_HOST",[170,1135,190],{"class":179},[170,1137,210],{"class":176},[170,1139,213],{"class":179},[12,1141,1142],{},"In template nodes:",[162,1144,1146],{"className":164,"code":1145,"language":166,"meta":155,"style":155},"API Endpoint: {{env.API_ENDPOINT}}\n",[21,1147,1148],{"__ignoreMap":155},[170,1149,1150,1153,1157,1160,1163,1166,1168,1171],{"class":172,"line":173},[170,1151,1152],{"class":176},"API ",[170,1154,1156],{"class":1155},"sBMFI","Endpoint",[170,1158,1159],{"class":179},":",[170,1161,1162],{"class":179}," {{",[170,1164,1165],{"class":176},"env",[170,1167,180],{"class":179},[170,1169,1170],{"class":176},"API_ENDPOINT",[170,1172,1173],{"class":179},"}}\n",[12,1175,1176,1177,1180],{},"For configuration nodes that don't have explicit environment variable support, you can often use the syntax ",[21,1178,1179],{},"${VARIABLE_NAME}"," in input fields.",[12,1182,1183,1186,1187,1190],{},[16,1184,1185],{},"Important note on precedence:"," When a flow-level and global-level environment variable share the same name, Node-RED uses the flow-level value. To explicitly access the global-level variable, prefix it with ",[21,1188,1189],{},"$parent."," in your reference.",[12,1192,1193,1196],{},[16,1194,1195],{},"Deleting environment variables:"," Return to the flow edit dialog where you added them and click the delete icon next to each variable. Remember to redeploy your flows after making changes.",[71,1198,1200],{"id":1199},"best-practices","Best Practices",[12,1202,1203],{},"Here are some guidelines for effective variable usage in Node-RED:",[12,1205,1206],{},[16,1207,1208],{},"Choose the right scope:",[974,1210,1211,1214,1217,1220],{},[140,1212,1213],{},"Use node variables for node-specific data",[140,1215,1216],{},"Use flow variables for data shared within a single workflow",[140,1218,1219],{},"Use global variables for system-wide shared data",[140,1221,1222],{},"Use environment variables for configuration and secrets",[12,1224,1225,1228,1229,52,1232,52,1235,1238],{},[16,1226,1227],{},"Naming conventions matter:"," Use clear, descriptive names. Consider prefixing variables with their purpose (e.g., ",[21,1230,1231],{},"sensor_temperature",[21,1233,1234],{},"config_timeout",[21,1236,1237],{},"user_preferences",").",[12,1240,1241,1244],{},[16,1242,1243],{},"Leverage persistent storage:"," For production applications, identify which variables need to survive restarts and use persistent storage for those.",[12,1246,1247,1250],{},[16,1248,1249],{},"Keep sensitive data in environment variables:"," Never hardcode API keys, passwords, or other secrets directly in flows. Always use environment variables.",[12,1252,1253,1256],{},[16,1254,1255],{},"Document your variables:"," Use the description field in your nodes to explain what variables are being set or read, especially for complex flows that others might maintain.",[12,1258,1259,1262],{},[16,1260,1261],{},"Monitor the Context Data panel:"," Regularly check this panel during development to verify variables are being set correctly and to catch potential issues early.",[71,1264,1266],{"id":1265},"conclusion","Conclusion",[12,1268,1269,1270,1273,1274,1277,1278,1281,1282,1284],{},"Node-RED's four variable types give you a clear toolkit for managing data and state. Use ",[16,1271,1272],{},"node context"," for private, node-specific values, ",[16,1275,1276],{},"flow variables"," for data shared within a single tab, and ",[16,1279,1280],{},"global variables"," for anything multiple flows need to reach. Reach for ",[16,1283,43],{}," when you're handling configuration and secrets that shouldn't be hardcoded. Matching the scope to the job keeps your flows organized, predictable, and easy for others to maintain.",[12,1286,1287],{},"The one thing to keep front of mind: context variables live in memory by default, so they reset on every restart or redeploy. For anything your application genuinely depends on, counters, cached configuration, dashboard history, plan for persistent storage from the start rather than discovering the gap in production.",[12,1289,1290],{},"Get the scopes right and lean on persistence where it matters, and Node-RED will handle everything from quick prototypes to applications you can run with confidence.",[1292,1293,1294],"style",{},"html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}",{"title":155,"searchDepth":1296,"depth":1296,"links":1297},4,[1298,1299,1302,1305,1308,1311,1312,1315,1316],{"id":73,"depth":216,"text":74},{"id":111,"depth":216,"text":112,"children":1300},[1301],{"id":125,"depth":658,"text":126},{"id":343,"depth":216,"text":344,"children":1303},[1304],{"id":356,"depth":658,"text":357},{"id":525,"depth":216,"text":526,"children":1306},[1307],{"id":538,"depth":658,"text":539},{"id":688,"depth":216,"text":689,"children":1309},[1310],{"id":698,"depth":658,"text":699},{"id":956,"depth":216,"text":957},{"id":1003,"depth":216,"text":1004,"children":1313},[1314],{"id":1025,"depth":658,"text":1026},{"id":1199,"depth":216,"text":1200},{"id":1265,"depth":216,"text":1266},{"type":1318,"title":1319,"description":1320},"signup","Take Your Node-RED Flows to Production with FlowFuse","Built by the team behind Node-RED, FlowFuse turns your flows into production-grade applications, with persistent state that survives restarts, centralized management of every instance, team collaboration with role-based access and SSO, DevOps pipelines, and built-in monitoring with crash alerts. Start your free trial today.","2024-05-06","Learn how to use Node-RED global, flow, context, and environment variables in 2026. Step-by-step examples for setting, retrieving, and persisting state, plus best practices and an FAQ.","md","\u002Fblog\u002F2024\u002F05\u002Fimages\u002Funderstanding-node-red-variables.png","2026-06-01",{"keywords":1327,"faq":1328,"excerpt":1353},"node-red variables, node-red global variable, node-red context variable, node-red flow variable, node-red environment variables",[1329,1332,1335,1338,1341,1344,1347,1350],{"question":1330,"answer":1331},"What are the different types of variables in Node-RED?","Node-RED has three main categories: message variables (like msg.payload) that travel with the message through nodes; context variables that store state at node, flow, or global scope; and environment variables for configuration and secrets. Context variables are further split into node, flow, and global scopes based on visibility.",{"question":1333,"answer":1334},"What is the difference between flow and global variables in Node-RED?","Flow variables are scoped to a single tab and are accessible to all nodes within that flow but isolated from other flows. Global variables are accessible across your entire Node-RED instance, making them suited for system-wide settings or data multiple flows need to share.",{"question":1336,"answer":1337},"How do I set a global variable in a Node-RED function node?","Use global.set('variableName', value) to store a value and global.get('variableName') to retrieve it. The same pattern applies to flow variables (flow.set \u002F flow.get) and node context (context.set \u002F context.get).",{"question":1339,"answer":1340},"Do Node-RED variables persist after a restart?","By default, all context variables are stored in memory and are lost on restart or redeploy. To keep them, use persistent storage by adding 'persistent' as the store option in the change node or as a third parameter in a function node, e.g. global.set('userData', userData, 'persistent'). FlowFuse provides persistent storage that survives restarts and redeployments.",{"question":1342,"answer":1343},"What is the difference between context variables and environment variables?","Context variables (node, flow, global) store runtime application state that changes as your flows run. Environment variables hold configuration data and sensitive information like API keys and credentials, kept separate from your flows for security and easier configuration management.",{"question":1345,"answer":1346},"What happens if a flow-level and global-level environment variable have the same name?","Node-RED uses the flow-level value when names collide. To explicitly access the global-level variable instead, prefix the reference with $parent. in your variable name.",{"question":1348,"answer":1349},"When should I use node context instead of flow or global variables?","Use node context for private, node-specific data such as counters or temporary calculations that no other node should access. Node variables exist only within a single function node, providing the most restrictive and isolated scope.",{"question":1351,"answer":1352},"How can I view all the variables currently set in Node-RED?","Open the Context Data panel from the sidebar dropdown. It shows all node, flow, and global variables in organized sections, lets you see when each was last updated, copy names or values, refresh individual variables, and delete them directly from the interface.",{"type":9,"value":1354},[1355],[12,1356,14,1357,19,1359,24,1361,28,1363,32,1365,36,1367,40,1369,44,1371,48,1373,52,1375,48,1377,59,1379,48,1381,66],{},[16,1358,18],{},[21,1360,23],{},[16,1362,27],{},[16,1364,31],{},[16,1366,35],{},[16,1368,39],{},[16,1370,43],{},[21,1372,47],{},[21,1374,51],{},[21,1376,55],{},[21,1378,58],{},[21,1380,62],{},[21,1382,65],{},true,"\u002Fblog\u002F2024\u002F05\u002Funderstanding-node-flow-global-environment-variables-in-node-red",{"title":5,"description":1322},{"loc":1384},"blog\u002F2024\u002F05\u002Funderstanding-node-flow-global-environment-variables-in-node-red","A complete guide to setting, retrieving, and persisting Node-RED variables for efficient, production-ready flows.",[1390,1391,1392],"posts","node-red","how-to","Node-RED offers four kinds of variables for managing data and state: message variables that travel with msg through nodes, and context variables in three scopes node (private to one function node), flow (shared within a tab), and global (shared across the whole instance) plus environment variables for configuration and secrets. You set and retrieve them with global.set\u002Fget, flow.set\u002Fget, and context.set\u002Fget in function nodes, or visually through the change node. Context variables live in memory by default and are lost on restart, so use persistent storage (FlowFuse provides this) for any state that must survive reboots and redeployments.",null,"JM0J3xiIkQQRtHldz5LdXINNjSanTuLf9BICQ6fXf24",[],1785528691574]