# Best way to save variables across node-red restarts?

**URL:** <https://discourse.nodered.org/t/best-way-to-save-variables-across-node-red-restarts/87315>\
**Category:** Developing Nodes\
**Created:** [18 April 2024 14:31 UTC](https://discourse.nodered.org/t/best-way-to-save-variables-across-node-red-restarts/87315 "2024-04-18T14:31:15Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [19 April 2024 11:57 UTC](https://discourse.nodered.org/t/best-way-to-save-variables-across-node-red-restarts/87315/4 "2024-04-19T11:57:09Z")

</div>

In the past, others have suggested using an MQTT broker (i.e. mosquito) that supports "retained messages" -- so when an `mqtt in` node connects to a topic it receives the last message that was sent to that topic.

I have not tried this myself, but it sounds pretty elegant and bullet-proof. Searching this forum for "mqtt retain context" yields many interesting threads, like this one: [Access to mqtt retained messages](https://discourse.nodered.org/t/access-to-mqtt-retained-messages/75914)

Edit: _in my pre-caffeine state, I failed to notice the category is "Developing Nodes" -- so this is probably not relevant to what you are doing_

---

_[View the full topic](https://discourse.nodered.org/t/best-way-to-save-variables-across-node-red-restarts/87315)._
