# Store variables in files for use in flow?

**URL:** https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360
**Category:** General
**Tags:** docker
**Created:** [12 August 2022 11:28 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360 "2022-08-12T11:28:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [12 August 2022 11:28 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/1 "2022-08-12T11:28:01Z")

</div>

Hello everyone!

I am currently working on a project where I want to store settings (e.g. "filter\_on = true") inside a textfile. I want to use these variables for later use in the flows, for example inside a switch-node.  
Currently, I am using the flow context:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1dd36e55314d6a8b87ebb1deeea738efccfc86c1.png)

So my main idea is to trigger a flow at start, where I put all these variables into the context. But I would prefer to read the values when they are used inside the flow (especially when I am working with Docker secrets). Is it possible to do this? Or do I have to create a new node for this?

Thanks in advance and have a nice weekend!

---

<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: [12 August 2022 11:34 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/2 "2022-08-12T11:34:46Z")

</div>

You can use ENV vars for secrets. Any where you can type `${MY_SECRET}` it will get converted in the runtime to the ENV VAR value.

If you want to read/write values from file, there are contrib nodes that already exist (search the flows lib)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [12 August 2022 11:36 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/3 "2022-08-12T11:36:54Z")

</div>

Is there a reason you don't want to use persistent context variables?

If you really do want to roll your own, put the data into a JS object so that you can store it as JSON (which is, I think, what the persistent context store does for you).

---

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [15 August 2022 06:04 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/4 "2022-08-15T06:04:55Z")

</div>

> [@TotallyInformation](#):
>
> Is there a reason you don't want to use persistent context variables?

Oh, I've never heard of persistent context before^^ I will definitely try this for my non-sensitive data

---

<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: [15 August 2022 08:29 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/5 "2022-08-15T08:29:35Z")

</div>

Here is something that may help you understand:

> [@A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115):
>
> This is something I wrote up after playing with the context options. I've filed a PR with some of this added to the Node-RED documentation but thought I'd release it here also. I hope people find it useful. Paul A guide to understanding 'Persistent Context' Prior to Node-RED v0.19.0, data could be stored in context as a global, flow or node. This was stored in memory and would be reset with a restart of Node-RED. As of v.0.19.0 you can now store node, flow and global context data in memory O…

---

<div class="post-metadata">

### Author: ![kitkat159](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kitkat159/32/66066_2.png) [@kitkat159](https://discourse.nodered.org/u/kitkat159)
#### Post date: [15 August 2022 08:41 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/6 "2022-08-15T08:41:52Z")

</div>

Thank you 🙂  
This post is way more helpful than the link provided in the settings.js

---

<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: [14 October 2022 08:41 UTC](https://discourse.nodered.org/t/store-variables-in-files-for-use-in-flow/66360/7 "2022-10-14T08:41:56Z")

</div>

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