# Is there any way to trace what node/routine is updating a global variable?

**URL:** <https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979>\
**Category:** General\
**Created:** [21 July 2023 02:55 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979 "2023-07-21T02:55:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 July 2023 02:55 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/1 "2023-07-21T02:55:47Z")

</div>

As the title says - i have a routine/function/change node buried deep somewhere that is changing a global variable - is there any smart way to find what this is ?

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 July 2023 03:11 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/2 "2023-07-21T03:11:17Z")

</div>

OK so first thing i tried was to Export all flows to json (formatted)

I then opened that in my editor and did a search for the variable name i was interested in and that gives me a list of them all - and then what type of node it was and also the Node ID - trying to work out how to find a node id and the flow it is on in the editor

Craig

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 July 2023 03:54 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/3 "2023-07-21T03:54:53Z")

</div>

Use the search bar and search for the node id. That will show you the flow it is on.  
If you then hover over the node icon and click on the magnifying glass on the left, it will take you to the correct location on the flow.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/6068dd88574deca3a71cd8de4a7d3de07cd5b3c0.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 July 2023 04:36 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/4 "2023-07-21T04:36:42Z")

</div>

Good one thanks - is there anyway to do it all in one step - or is my first step of doing the export the right way to go ?

Craig

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 July 2023 10:38 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/5 "2023-07-21T10:38:43Z")

</div>

Sure just use a code snippet like this example

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1c554e2aaaa62afc17e6f846dfe797b394fa9fa2.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 July 2023 11:01 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/6 "2023-07-21T11:01:40Z")

</div>

Just search `ctrl+f` for the name then use `f` to step through each found node

Or use the the 🔍 toolbar at the bottom of the flow canvas and the `<<` & `>>` button that appear after executing a search.

Better still, don't update globals from multiple locations (bad programming practice 101). Instead, use link nodes or subflows to update globals in 1 place.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 July 2023 11:25 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/7 "2023-07-21T11:25:23Z")

</div>

@craigcurtin Also, if you set the global value add some meta data, e.g. time updated and where/what updated the value, you would find it easier to see what, where and when the global was updated in the future.

[edit] sorry reply was not meant for you @smcgann99 pressed wrong reply button

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 July 2023 14:16 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/8 "2023-07-21T14:16:07Z")

</div>

> [@Steve-Mcl](#):
>
> Better still, don't update globals from multiple locations

Arguably even more betterer don't use global/flow context unless it is not practical to achieve the result by passing values via messages.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 July 2023 14:26 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/9 "2023-07-21T14:26:39Z")

</div>

Agreed 100%

I feel folk reach for globals (and are informed to use globals) far more than they should.

There are times where context makes sense, but in many cases, context can (and should) be avoided

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 July 2023 00:29 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/10 "2023-07-24T00:29:11Z")

</div>

Hmm,

Globals seem like a very sensible solution to a lot of situations though - as an example i download our power prices every 5 minutes (as we are on a wholesale variable rate) - this is a large array that holds a lot of inforomation.

I then use this across a number of other areas where i have to make decisions based on the current power price (should i charge the EV) should i run the Heatpump in the next 1/2 hour etc etc

Each of these functions are broken into seperate flows to keep them neat and to reflect what they are doing - in my case the Global context appears to be ideal for this - plus it allows me to drill down from any flow and see what values may be being used by other flows

But i do like the idea of updating the Global variables to note what updated them and when - i will go back and redo a lot of my stuff to reflect this.

Craig

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 August 2023 00:29 UTC](https://discourse.nodered.org/t/is-there-any-way-to-trace-what-node-routine-is-updating-a-global-variable/79979/11 "2023-08-07T00:29:40Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
