# How to implement custom context store

**URL:** <https://discourse.nodered.org/t/how-to-implement-custom-context-store/77994>\
**Category:** General\
**Created:** [28 April 2023 00:14 UTC](https://discourse.nodered.org/t/how-to-implement-custom-context-store/77994 "2023-04-28T00:14:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![88bit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/88bit/32/79334_2.png) [@88bit](https://discourse.nodered.org/u/88bit)\
**Post date:** [28 April 2023 00:14 UTC](https://discourse.nodered.org/t/how-to-implement-custom-context-store/77994/1 "2023-04-28T00:14:37Z")

</div>

Node\_Red version 3.0.2

Hi all, I'm trying to implement a custom context store. I have read the documentation however I'm still unsure how to edit the settings.js file to create these stores, and I have the following question

1. Can I create multiple context stores e.g. Store\_1 (in memory), Store\_2 (in memory), Store\_3 (on disk)?
2. How do I implement the "require" statement in the flows?

Can someone point me in the right direction so I can find an example that shows an example with multiple context stores implemented in the settings.js file?

Here is the example from the help files. I'm also unsure where to place the "required" statement in my flow.

The `module` property identifies the context store plugin to use. It can either be the name of built-in module (currently either `memory` or `localfilesystem` ), or it should be a module that has been loaded using `require` .

```auto
contextStorage: {
   default: {
       module:"memory",
   },
   custom: {
       module:require("my-custom-store")
   }
}

```

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [28 April 2023 01:01 UTC](https://discourse.nodered.org/t/how-to-implement-custom-context-store/77994/2 "2023-04-28T01:01:44Z")

</div>

You need to edit settings.js find this section, and edit to look something like this -

```auto
contextStorage: {
   default: "Store_1",
   Store_1: { module: 'memory' },
   Store_2: { module: 'memory' },
   Store_3: { module: 'localfilesystem' }
}

```

> [@88bit](#):
>
> I'm also unsure where to place the "required" statement in my flow.

This is not needed its configured in the settings.js file. Store\_1 will be used by default. To use another in a function node you specify it after the name of the variable like this -

```auto
flow.get("detail", "Store_2")

```

In other nodes where supported you can pick from your list -  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/dbd4d3a941f0d1185b45734ee21cbf7b3be58380.png)

I would recommend including mem or file in the names, so you know which is which though.  
Also not sure why you would want 2 memory stores ?

---

<div class="post-metadata">

**Author:** ![88bit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/88bit/32/79334_2.png) [@88bit](https://discourse.nodered.org/u/88bit)\
**Post date:** [28 April 2023 08:47 UTC](https://discourse.nodered.org/t/how-to-implement-custom-context-store/77994/3 "2023-04-28T08:47:40Z")

</div>

Thank you, very detailed and clear explanation. It is so wonderful to see this community support.

---

<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:** [12 May 2023 08:47 UTC](https://discourse.nodered.org/t/how-to-implement-custom-context-store/77994/4 "2023-05-12T08:47:40Z")

</div>

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