# Context file not written when using multiple localfilesystem entries

**URL:** <https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617>\
**Category:** General\
**Created:** [2 December 2022 16:09 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617 "2022-12-02T16:09:03Z")\
**Posts on this page:** 15\
**Page:** 3

<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:** [6 December 2022 21:20 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/42 "2022-12-06T21:20:09Z")

</div>

> [@interscope101](#):
>
> I am not sure what takes place on load (whatever was set on install),

It seems that you are using PM2 to run node-red. I don't use PM2, it isn't the recommended way with Ubuntu, but if you want to use it then it is up to you to make sure you know how to use it. Somewhere in the setup I would expect that you set a user that the node-red process runs under.

> [@interscope101](#):
>
> I have various node in the applications that are writing files in the /home/ubuntu directory.

Do you mean that you write to that folder from inside node-red? If so then it probably isn't a permission problem.

---

<div class="post-metadata">

**Author:** ![interscope101](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@interscope101](https://discourse.nodered.org/u/interscope101)\
**Post date:** [6 December 2022 21:27 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/43 "2022-12-06T21:27:41Z")

</div>

> [@Colin](#):
>
> Do you mean that you write to that folder from inside node-red? If so then it probably isn't a permission problem.

Correct. Plus I don't have a problem with just default single file store and we see other data being written. Could there be an issue with config "directory" parameters - they are being ignored and some kind of files are being created with data written in default context folder (in a mixed up way).

---

<div class="post-metadata">

**Author:** ![interscope101](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@interscope101](https://discourse.nodered.org/u/interscope101)\
**Post date:** [6 December 2022 21:39 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/44 "2022-12-06T21:39:14Z")

</div>

> [@Colin](#):
>
> It seems that you are using PM2 to run node-red. I don't use PM2, it isn't the recommended way with Ubuntu, but if you want to use it then it is up to you to make sure you know how to use it. Somewhere in the setup I would expect that you set a user that the node-red process runs under.

Perhaps you should mention that it's not recommended in the guide section - that's how I ended up with this set up since I was using ec2/ubuntu configuration.

[https://nodered.org/docs/getting-started/aws#running-on-aws-ec2-with-ubuntu](https://nodered.org/docs/getting-started/aws#running-on-aws-ec2-with-ubuntu)

Regardless, do you believe there is a bug related to using multiple file stores?

---

<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:** [6 December 2022 21:42 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/45 "2022-12-06T21:42:27Z")

</div>

> [@interscope101](#):
>
> I don't have a problem with just default single file store

That is going to a different folder, in the .node-red heirarchy. You have specified that the others go to a different folder (node-red without the dot.) They are both under the same user home folder though.

What does these commands show  
`ls -al /home/ubuntu/node-red`  
`ls -al /home/ubuntu/.node-red`

Try creating the directories that you have told it to save the context in. I can't test your flow till the morning.

---

<div class="post-metadata">

**Author:** ![interscope101](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@interscope101](https://discourse.nodered.org/u/interscope101)\
**Post date:** [6 December 2022 21:48 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/46 "2022-12-06T21:48:04Z")

</div>

I did create those directories. And just to be certain (there was no some overlooked permission issue in that particular sub-directory (/home/ubuntu/node-red) I changed the directory to (/home/ubuntu) and that's where I have other nodes (like exec node) writing/creating files without issues.

I did the same inject/change node test and got the same outcome. It is really strange, after restart all three context stores get populated with a value that was stored in one of them (same one as before)

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

---

<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:** [6 December 2022 22:11 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/47 "2022-12-06T22:11:40Z")

</div>

I can confirm that the alternate folder settings for storage do not work.

settings.js

```auto
    contextStorage: {
        default: {
            module:'memory',
        },
        file: {
            module: 'localfilesystem',
            // config: {
            // flushInterval: '10', // default is 30s
            // },
        },
        altFile: { 
            module: 'localfilesystem', 
            dir: '/home/julian/nrAltFileStore',
        }
    },

```

Flow

```auto
[{"id":"1d32ca5b3fdd573d","type":"inject","z":"8f633713fe222323","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":240,"wires":[["07688e5a74b5e1eb"]]},{"id":"07688e5a74b5e1eb","type":"change","z":"8f633713fe222323","name":"","rules":[{"t":"set","p":"test1","pt":"flow","to":"This is the default store - a flow var","tot":"str"},{"t":"set","p":"#:(file)::test2","pt":"flow","to":"This is the file store - a flow var","tot":"str"},{"t":"set","p":"#:(altFile)::test3","pt":"flow","to":"This is the altFile store - a flow var","tot":"str"},{"t":"set","p":"test4","pt":"global","to":"This is the default store - a global var","tot":"str"},{"t":"set","p":"#:(file)::test5","pt":"global","to":"This is the file store - a global var","tot":"str"},{"t":"set","p":"#:(altFile)::test6","pt":"global","to":"This is the altFile store - a global var","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":240,"wires":[["6e468a657e5df5d3"]]},{"id":"6e468a657e5df5d3","type":"debug","z":"8f633713fe222323","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":240,"wires":[]}]

```

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

Nothing appears in `/home/julian/nrAltFileStore`.

Latest node-red running under Debian (via WSL).

---

<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:** [6 December 2022 22:22 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/48 "2022-12-06T22:22:38Z")

</div>

On a later re-run I did get an error - but related to the flow variable to the `file` context store:

```auto
Welcome to Node-RED
===================
6 Dec 22:18:29 - [info] Node-RED version: v3.0.2
6 Dec 22:18:29 - [info] Node.js version: v16.18.1
6 Dec 22:18:29 - [info] Linux 5.15.74.2-microsoft-standard-WSL2 x64 LE
6 Dec 22:18:29 - [info] Loading palette nodes
6 Dec 22:18:29 - [info] Settings file : /home/julian/nrlive/data/settings.js
6 Dec 22:18:29 - [info] HTTP Static : /home/julian/nrlive/public > /
6 Dec 22:18:29 - [info] Context store : 'default' [module=memory]
6 Dec 22:18:29 - [info] Context store : 'file' [module=localfilesystem]
6 Dec 22:18:29 - [info] Context store : 'altFile' [module=localfilesystem]
6 Dec 22:18:29 - [info] User directory : /home/julian/nrlive/data
6 Dec 22:18:29 - [warn] Projects disabled : editorTheme.projects.enabled=false
6 Dec 22:18:29 - [info] Flows file : /home/julian/nrlive/data/flows.json
6 Dec 22:18:29 - [info] Server now running at http://127.0.0.1:1881/red/
6 Dec 22:18:29 - [info] Starting flows
6 Dec 22:18:29 - [info] Started flows
6 Dec 22:18:49 - [info] Stopping flows
6 Dec 22:18:49 - [info] Stopped flows
6 Dec 22:18:49 - [info] Updated flows
6 Dec 22:18:49 - [info] Starting flows
6 Dec 22:18:49 - [info] Started flows
6 Dec 22:19:22 - [error] Error writing context: Error: ENOENT: no such file or directory, rename '/home/julian/nrlive/data/context/8f633713fe222323/flow.json.1670365162017.tmp' -> '/home/julian/nrlive/data/context/8f633713fe222323/flow.json'

```

And here is what I found in the file:

```auto
{
    "test2": "This is the file store - a flow var"
} "test3": "This is the altFile store - a flow var - 2"
}

```

Oops!

I had changed the node-red settings to this (and restarted):

```auto
    contextStorage: {
        default: {
            module:'memory',
        },
        file: {
            module: 'localfilesystem',
            // config: {
            // flushInterval: '10', // default is 30s
            // },
        },
        altFile: { 
            module: 'localfilesystem', 
            dir: '/home/julian/nrAltFileStore',
            base: 'context',
            cache: false,
            flushInterval: 1,
        }
    },

```

---

<div class="post-metadata">

**Author:** ![interscope101](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@interscope101](https://discourse.nodered.org/u/interscope101)\
**Post date:** [6 December 2022 22:28 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/49 "2022-12-06T22:28:45Z")

</div>

Do you see (after restart) the same data being written in both ?

Does the "base" need to be specified?

---

<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:** [6 December 2022 22:31 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/50 "2022-12-06T22:31:49Z")

</div>

> [@interscope101](#):
>
> Do you see (after restart) the same data being written in both ?

Not quite, you can see what it wrote - to the wrong place.

> [@interscope101](#):
>
> Does the "base" need to be specified?

I added the other properties to see if that made a difference.

There is clearly a bug when using a local file store with a different directory. We need to let the devs have a look when they can so that they can fix.

---

<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:** [6 December 2022 23:17 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/51 "2022-12-06T23:17:18Z")

</div>

Would one of you guys be kind enough to raise an issue on the node-red repo please & I'll check it out.

Thanks.

---

<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:** [6 December 2022 23:29 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/52 "2022-12-06T23:29:34Z")

</div>

Done.

> <https://github.com/node-red/node-red/issues/3975>
>
> \### Current Behavior
> 
> Please see https://discourse.nodered.org/t/multiple-localf…ilesystems/71617/48
> 
> All details there.
> 
> \### Expected Behavior
> 
> \_No response\_
> 
> \### Steps To Reproduce
> 
> \_No response\_
> 
> \### Example flow
> 
> \`\`\`
> paste your flow here
> \`\`\`
> 
> 
> \### Environment
> 
> \- Node-RED version: 3.0.2
> \- Node.js version: 16.18.1
> \- npm version:
> \- Platform/OS: Windows 10/WSL2/Debian - \`Linux 5.15.74.2-microsoft-standard-WSL2 x64 LE\`
> \- Browser: Edge 107.0.1418.62 (Official build) (64-bit)

Sorry, details a bit light as it is late but all details are in this thread.

---

<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:** [4 February 2023 23:29 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/53 "2023-02-04T23:29:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 March 2023 17:02 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/54 "2023-03-02T17:02:53Z")

</div>



---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 March 2023 17:06 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/55 "2023-03-02T17:06:26Z")

</div>

Finally got around to investigating this properly.

Everything is working as designed. The problem in this thread was I gave bad advice in my comment right at the start over how to properly configure multiple file stores.

I said to use the following configuration:

```auto
contextStorage: {
   default: "memoryOnly",
   memoryOnly: { module: 'memory' },
   file: { module: 'localfilesystem', dir: '/home/user/.node-red/context1' },
   file2: { module: 'localfilesystem', dir: '/home/user/.node-red/context2' },
   file3: { module: 'localfilesystem', dir: '/home/user/.node-red/context3' }
},

```

Had I read the [docs I wrote](https://nodered.org/docs/api/context/store/localfilesystem#configuration) I would have spotted that the configuration options must be under a `config` object:

```auto
contextStorage: {
   default: "memoryOnly",
   memoryOnly: { module: 'memory' },
   file: {
      module: 'localfilesystem',
      config: {
         dir: '/home/user/.node-red/context1'
      }
   },
   file2: {
      module: 'localfilesystem',
      config: {
         dir: '/home/user/.node-red/context2'
      }
   }
},

```

---

<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:** [16 March 2023 17:07 UTC](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617/56 "2023-03-16T17:07:23Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/context-file-not-written-when-using-multiple-localfilesystem-entries/71617.md?page=2)
