Store a full message and retreive at node-red start time


I have a Node-RED function node that outputs a message periodically. I would like to save this message to a file so that if Node-RED restarts, I can retrieve the last saved message but cannot inject it back into the function node when Node-RED starts up again.

The issue I'm running into is that when Node-RED restarts, the previous message in the function node gets cleared out. I need a way to persistently store the message from the function node so that it is not lost on restart.

My thought is to have the function node write its output message to a file periodically. Then on Node-RED startup, I can read the last saved message from that file and inject it into the function node to pick up where it left off before the restart. This would prevent losing the message and state on a restart. But I tried and not working.

Please let me know if you have any suggestions on the best approach to persistently store the message from the function node and re-inject it on startup.



Use persistent context or DIY it with file nodes.


Thank you @Steve-Mcl for the suggestion. I tried using a file node to retrieve the message, but I'm struggling with how to properly inject it back into my function node.

Use an inject node set to fire on startup to trigger the read.

Persistent context would probably be a much simpler solution.

1 Like

Persistent context means adding module in setting.js ?

Have you read the documentation? Take a read of this: and then if you don't understand ask.

You can also read this post I made quite awhile ago: (A guide to understanding 'Persistent Context')


Looking at your other post, it seems that the data you want to retrieve at startup originates in a database.

Rather than storing this data in Node-red persistent context or in a file, why can't you recover it from the database?

Thank you @all ,I will use Persistent context

1 Like