How to get where a specific global variable is used?

Hi to all,
I'm rookie on Node-red variable.
I'm using some specifics global variables. they are spred on several flows and I need to know where they are used in my flows.
So, I wonder if there's a way to get where those global variables are used, due to documentation writting.
Thank you in advance

Hi Denis, welcome to the forum.

Other than using "search" no. I would like to point out that it is possible to overuse globals.

Alternative approaches can help keep things in one place. e.g:

  1. Dont use globals (pass values in the msg object)
  2. Use flow to limit scope to one flow. If you need access to them on another flow, use link nodes
  3. Use a database instead of global context

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Welcome to the forum @DenisCeleghin

I see @Steve-Mcl has already said this but...
Using lots of global variables is IMHO a rookie mistake because

  • It subverts the flow based architecture of Node-red. You can make fundamental changes in another flow by changing a global variable.
  • You cannot rely on a global variable's value remaining stable over the duration of a flow.
  • It's not so easy to find where the variable is referenced. There is a search function, so long as you used a unique variable name.

Thank you so much,
I think that using database instead of global context it would be better.
In the next proj I shall follow your suggestion.
Anyway, I've alredy deployed my proj in porduction and the customer is using it.
I decided to use global variable as configuration variable, and from the design process point of view, they don't change their value during the process. I took advantage the fact that the global variables scope is cross flows.
As far as I understood, there is the possibility to get the info that I need checking inside flow.json file, in order to get them, but it's pretty hard.
Again thank you.

Hi jbudd,
thank you so much.
Regarding "There is a search function, so long as you used a unique variable name.", could you please explain which is this search function mentioned in your reply?
Thank you in advance.

If the values dont change at runtime, then ENV VARs are a better fit.

Search = CTRL-F then enter the name of your variable. If your global variable is named x you are gonna have a touch time, if it is uniquely named SETTING_HEIGHT_VALUE then it will be easy to find

Hi Steve-Mcl,
"If the values don't change at runtime, then ENV VARs are a better fit."
I used them for setting the db connection parameters. For the global variables, I provided a user dashboard in ngnix for the porpouse of changing some settings (i.e. TRUE/FALSE YES/NO). However, I think that it would be better to move everything to db instead of using global vars.

You can open the search dialog from the hamburger menu at the top right of the editor too.

And via the magnifying glass :magnifying_glass_tilted_left: in the footer

Hi Steve-Mcl,
thank you very much for your help.
Have a nice day.

Hi jbudd,
thank you very much for your help.
Have a nice day.

Just to quickly add to this.

When I use globals, I typically try to use a single, more complex object rather than lots of shallow variables.

One of the advantages is that it lets you extend the schema. If my variable will be used from lots of places, I will often extend the schema to add updated and updatedBy properties so that I can clearly see when things were last updated and by what section of my flows.

I use an equivalent with MQTT as well. Indeed, I will often mirror globals with MQTT topic structures so that I have the current values and have triggered updates.

By using these capabilities, along with retained variables and topics, I hardly ever need a database unless storing more info than would easily fit into memory.

1 Like