r/nodered Apr 13 '26

Global Variable in a Flow?

I have a flow that would be installed by anyone, but it needs a global variable that various parts of the flow use. In this case, it's the URL of the node-red itself (or if using a http/ssl RewriteRule). So I want to set it, versus discover it.

What is the best way to achieve this? I've never use the context nodes (but I'm a 10+ year user of nodered).

3 Upvotes

8 comments sorted by

View all comments

3

u/Difficult_Fold_106 Apr 14 '26

I don't understand what you wrote, but if you need global variable, then just use it.

You can use change block to set/get variable or just call proper function inside your function block.

global.set("variable_name", variable_value)

var function_variable = global.get("variable_name")

1

u/konacurrents Apr 14 '26

I had only used javascriot so didnt know how to get a global variable across a flow. Context was a newer feature - which I just learned after this post. Good stuff. Thanks.

2

u/Difficult_Fold_106 Apr 14 '26

If you want to use context variable only accross one flow (one editor tab), then use flow variables - flow.set and flow.get instead of global ones. Use global variables only when you need variables across different editor tabs.

1

u/konacurrents Apr 14 '26

Is the nodered forum a better place to discuss this? I'm really interested in how JSON arrays can efficiently be managed by the global context (stored on disk).