Get flow variable on node close callback


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.


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.


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.

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.

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.

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... :thinking:

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

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