# Get flow variable on node close callback

**URL:** <https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823>\
**Category:** General\
**Created:** [17 February 2020 03:41 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823 "2020-02-17T03:41:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dathor](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dathor](https://discourse.nodered.org/u/dathor)\
**Post date:** [17 February 2020 03:41 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/1 "2020-02-17T03:41:53Z")

</div>

Hello

I would like to persist some runtime data when my node-red application shuts down. To do this I have created a node close callback.

`node.on("close", function(done) { ... done() }`

My question is, can i access a flow variable from the close callback. It does not seem to work, my flow var is empty.

Thanks

---

<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:** [17 February 2020 07:18 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/2 "2020-02-17T07:18:44Z")

</div>

I don't know the answer to the question, but if you tell us a bit more about the data you want to persist we may be able to suggest a better solution. I presume you already know that flow and context data can be persisted automatically.

---

<div class="post-metadata">

**Author:** ![dathor](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dathor](https://discourse.nodered.org/u/dathor)\
**Post date:** [17 February 2020 11:02 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/3 "2020-02-17T11:02:28Z")

</div>

Hi

Thanks for you comments. The data is active alarms from an automation system. When the flow shuts down i wanted to complete all the active alarm's (calculate the duration) and persist. When the flow starts up i then get the persisted completed alarms and push them to the history database.

Yes, i guess one solution would be to 'store to file' the active alarms flow variable. I just thought that is was cleaner or nicer to not be continually writing to the file system.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [17 February 2020 15:05 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/4 "2020-02-17T15:05:36Z")

</div>

> [@dathor](#):
>
> My question is, can i access a flow variable from the close callback. It does not seem to work, my flow var is empty.

It should be possible. But without specific details of what you've tried, it's hard to say why it isn't working for you.

---

<div class="post-metadata">

**Author:** ![dathor](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dathor](https://discourse.nodered.org/u/dathor)\
**Post date:** [18 February 2020 04:49 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/5 "2020-02-18T04:49:57Z")

</div>

Hello Thanks,

Problem solved, because my flow variable was declared in a subflow i think i was just getting a bit confused with what instance i was looking at.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [18 February 2020 07:27 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/6 "2020-02-18T07:27:35Z")

</div>

I don't quite get where/how you have registered the close handler? I assumed you created a custom node, but then you mentioned subflows... 🤔

---

<div class="post-metadata">

**Author:** ![dathor](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dathor](https://discourse.nodered.org/u/dathor)\
**Post date:** [18 February 2020 10:11 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/7 "2020-02-18T10:11:48Z")

</div>

I registered the close handler in a function node used inside a sub flow.

---

<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:** [18 April 2020 10:14 UTC](https://discourse.nodered.org/t/get-flow-variable-on-node-close-callback/21823/8 "2020-04-18T10:14:04Z")

</div>

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