# Local Context Storage not working

**URL:** <https://discourse.nodered.org/t/local-context-storage-not-working/94287>\
**Category:** General\
**Tags:** docker\
**Created:** [1 January 2025 13:37 UTC](https://discourse.nodered.org/t/local-context-storage-not-working/94287 "2025-01-01T13:37:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjm9](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jjm9](https://discourse.nodered.org/u/jjm9)\
**Post date:** [1 January 2025 13:37 UTC](https://discourse.nodered.org/t/local-context-storage-not-working/94287/1 "2025-01-01T13:37:57Z")

</div>

Hey there,

before starting, I'd like to give you some infos about my setup.

Node-RED v4.0.8 running under Docker  
mounted local folder to /tmp in container.

I wanted to activated local content storage to be able to store context in local filesystem.  
The [docs](https://nodered.org/docs/api/context/store/localfilesystem#implementation-details) are pretty straight forward.  
I added this to my settings.js:

```auto
contextStorage: {
    default: {
        module: "memory"
    },
    file: {
        module: "localfilesystem",
        config: {
            dir: "/tmp"
        }
    }
},

```

So writing seems to work, right?  
My problem is, I cannot retrieve the stored files.

```auto
const average = msg.payload || 0; 

// Wert im Flow-Kontext aktualisieren
flow.set("LastPvPowerAverage", average);

// Wert im Datei-Kontext speichern
context.set("LastPvPowerAverage", average, "file");

//node.warn(`Gespeichert: ${average}`);
return msg;

```

With this function, I can store the input of the function node. I verified this on the filesystem.

When trying to retrieve it with this:

```auto
const lastAverage = context.get("LastPvPowerAverage", "file"); // Versuche, den Wert aus der Datei zu laden
if (lastAverage !== undefined) {
    node.warn(`Erfolgreich abgerufen: ${lastAverage}`);
    flow.set("LastPvPowerAverage", lastAverage); // In den Flow-Kontext speichern
    node.status({ fill: "blue", shape: "ring", text: `Initialisiert: ${lastAverage}` });
} else {
    node.warn("Kein gespeicherter Wert gefunden!");
    flow.set("LastPvPowerAverage", 0); // Standardwert setzen
    node.status({ fill: "red", shape: "ring", text: "Kein Wert gespeichert" });
}
return null;

```

I dont get anything at all.

Any help Is appreciated on troubleshooting this situation.

---

<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:** [1 January 2025 13:48 UTC](https://discourse.nodered.org/t/local-context-storage-not-working/94287/2 "2025-01-01T13:48:27Z")

</div>

Is that 2nd code segment in the same function node as the 1st? If not, then you should be using `flow` or `global` instead of `context`.

---

<div class="post-metadata">

**Author:** ![jjm9](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jjm9](https://discourse.nodered.org/u/jjm9)\
**Post date:** [1 January 2025 14:00 UTC](https://discourse.nodered.org/t/local-context-storage-not-working/94287/3 "2025-01-01T14:00:07Z")

</div>

Oh hell, you dont not how much I appreciate your help!  
As it were two different function nodes, your solution helped me out!  
thanks so much!

---

<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 January 2025 14:00 UTC](https://discourse.nodered.org/t/local-context-storage-not-working/94287/4 "2025-01-15T14:00:57Z")

</div>

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