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

**URL:** <https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040>\
**Category:** General\
**Created:** [15 October 2023 06:59 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040 "2023-10-15T06:59:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thahamp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thahamp/32/82149_2.png) [@thahamp](https://discourse.nodered.org/u/thahamp)\
**Post date:** [15 October 2023 06:59 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/1 "2023-10-15T06:59:48Z")

</div>

Hello,

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.

```auto
[{"potNumber":137,"anodeNumber":8,"eventBoxes":[{"box_id":"1_137_8","id":1,"event":"CrustBreaker","PotNum":137,"AnodeNum":8,"StartTime":"10:48:38","StartDate":"10/15/2023","StopTime":"10:48:39","StopDate":"10/15/2023","EventDuration":1,"flowId":1},{"box_id":"3_137_8","id":3,"event":"AnodeRemoval","PotNum":137,"AnodeNum":8,"StartTime":"10:48:45","StartDate":"10/15/2023","StopTime":"10:48:49","StopDate":"10/15/2023","EventDuration":4,"flowId":1},{"box_id":"6_137_8","id":6,"event":"CavityScoop","PotNum":137,"AnodeNum":8,"StartTime":"10:48:51","StartDate":"10/15/2023","StopTime":"10:48:53","StopDate":"10/15/2023","EventDuration":2,"flowId":1},{"box_id":"9_137_8","id":9,"event":"NewAnodeInstall","PotNum":137,"AnodeNum":8,"StartTime":"10:49:31","StartDate":"10/15/2023","StopTime":"10:49:32","StopDate":"10/15/2023","EventDuration":1,"flowId":1}],"sequenceComplete":1,"currentSequencePosition":4}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75d9982786b5a9b2e7e29e958f72c3c483ab3cde.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:** [15 October 2023 07:06 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/2 "2023-10-15T07:06:05Z")

</div>

Use persistent context or DIY it with file nodes.

---

<div class="post-metadata">

**Author:** ![thahamp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thahamp/32/82149_2.png) [@thahamp](https://discourse.nodered.org/u/thahamp)\
**Post date:** [16 October 2023 02:42 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/3 "2023-10-16T02:42:22Z")

</div>

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.

---

<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:** [16 October 2023 07:04 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/4 "2023-10-16T07:04:38Z")

</div>

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

Persistent context would probably be a much simpler solution.

---

<div class="post-metadata">

**Author:** ![thahamp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thahamp/32/82149_2.png) [@thahamp](https://discourse.nodered.org/u/thahamp)\
**Post date:** [16 October 2023 07:55 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/5 "2023-10-16T07:55:31Z")

</div>

> [@Colin](#):
>
> Persistent context

Persistent context means adding module in setting.js ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 October 2023 08:04 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/6 "2023-10-16T08:04:12Z")

</div>

Have you read the documentation? Take a read of this: [https://nodered.org/docs/user-guide/contexttake](https://nodered.org/docs/user-guide/contexttake) 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'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115))

---

<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:** [16 October 2023 08:45 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/7 "2023-10-16T08:45:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![thahamp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thahamp/32/82149_2.png) [@thahamp](https://discourse.nodered.org/u/thahamp)\
**Post date:** [16 October 2023 09:45 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/8 "2023-10-16T09:45:40Z")

</div>

Thank you @all ,I will use **Persistent context**

---

<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:** [15 December 2023 09:46 UTC](https://discourse.nodered.org/t/store-a-full-message-and-retreive-at-node-red-start-time/82040/9 "2023-12-15T09:46:13Z")

</div>

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