# Reset global (or) flow counter values when session is closed

**URL:** <https://discourse.nodered.org/t/reset-global-or-flow-counter-values-when-session-is-closed/76228>\
**Category:** General\
**Tags:** function-node\
**Created:** [7 March 2023 11:58 UTC](https://discourse.nodered.org/t/reset-global-or-flow-counter-values-when-session-is-closed/76228 "2023-03-07T11:58:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rchandrashekar53](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rchandrashekar53/32/60423_2.png) [@rchandrashekar53](https://discourse.nodered.org/u/rchandrashekar53)\
**Post date:** [7 March 2023 11:58 UTC](https://discourse.nodered.org/t/reset-global-or-flow-counter-values-when-session-is-closed/76228/1 "2023-03-07T11:58:12Z")

</div>

i am looking for an approach where my counter values are reset when the session of my flow is closed (or) node red server is turned off.

in my current implementation i am using-

```auto
global.set("counter",1);

```

and then i increment the counter value based on a condition. When i relaunch the node-red server - i see that the last saved value of the counter is still saved.

Is there a way i can reset the value when the session is closed?

---

<div class="post-metadata">

**Author:** ![rchandrashekar53](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rchandrashekar53/32/60423_2.png) [@rchandrashekar53](https://discourse.nodered.org/u/rchandrashekar53)\
**Post date:** [7 March 2023 11:58 UTC](https://discourse.nodered.org/t/reset-global-or-flow-counter-values-when-session-is-closed/76228/2 "2023-03-07T11:58:52Z")

</div>

i also tried

```auto
flow.get();

```

same results

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [7 March 2023 12:04 UTC](https://discourse.nodered.org/t/reset-global-or-flow-counter-values-when-session-is-closed/76228/3 "2023-03-07T12:04:51Z")

</div>

You can use a change node to set or delete a context variable. It could be triggered by an inject node set to fire at startup.

How many global context variables are you using?

---

<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:** [6 May 2023 12:05 UTC](https://discourse.nodered.org/t/reset-global-or-flow-counter-values-when-session-is-closed/76228/4 "2023-05-06T12:05:11Z")

</div>

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