# Saving flows into Database

**URL:** <https://discourse.nodered.org/t/saving-flows-into-database/30549>\
**Category:** General\
**Created:** [22 July 2020 13:06 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549 "2020-07-22T13:06:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [22 July 2020 13:06 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/1 "2020-07-22T13:06:37Z")

</div>

Hi, I have checked out the Storage module. Can anyone help me out if there are any samples of storing flows into postgresql or mongoDB?

I have seen - [https://nodered.org/docs/api/storage/methods/#storagesaveflowsflows](https://nodered.org/docs/api/storage/methods/#storagesaveflowsflows)

Thanks!

---

<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:** [22 July 2020 13:08 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/2 "2020-07-22T13:08:39Z")

</div>

Are you saying you want to store the active flow into a database?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 July 2020 13:10 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/3 "2020-07-22T13:10:16Z")

</div>

There are some examples of Node-RED storage plugins out there - can't put my finger on them right now - but hey do exist.

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [22 July 2020 13:34 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/4 "2020-07-22T13:34:44Z")

</div>

Yes. I want to store flows into database.

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [22 July 2020 13:35 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/5 "2020-07-22T13:35:28Z")

</div>

I have found a mongodb plugin but can't seem to understand how to store the flows into the database.

---

<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:** [23 July 2020 00:06 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/6 "2020-07-23T00:06:38Z")

</div>

Well you first have to get the flow file. This could be tricky if you don't have the flow file name set in settings.js because Node-RED uses `flows_<hostname>.json` as the default flows file. That is as long as you do not have 'projects' active.

Once you know the name of the flow, you can use the file node or one of the contrib file nodes to read the file. You can tehn pass that to your database node to save. Don't forget you also need to save the `flows_<hostname>_cred.json` file also.

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [23 July 2020 05:12 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/7 "2020-07-23T05:12:27Z")

</div>

Thank you. Isn't there any module to directly do this process from node-red to DB?

---

<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:** [23 July 2020 05:24 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/8 "2020-07-23T05:24:27Z")

</div>

> [@poojak](#):
>
> I have found a mongodb plugin

What mongodb plugin did you find? Was it a storage plugin or just a regular Node-RED node module?

There is an storage plugin for the Cloudant database here: [node-red-app/cloudantStorage.js at master · IBM/node-red-app · GitHub](https://github.com/IBM/node-red-app/blob/master/cloudantStorage.js)

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [23 July 2020 05:34 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/9 "2020-07-23T05:34:36Z")

</div>

It was from this article - [https://www.npmjs.com/package/node-red-mongo-storage-plugin](https://www.npmjs.com/package/node-red-mongo-storage-plugin)  
Wasn't useful for me though.

Thanks for sharing the storage plugin.

---

<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:** [23 July 2020 05:46 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/10 "2020-07-23T05:46:46Z")

</div>

Why was that module not useful? It's exactly what you asked for - a storage plugin for Node-RED that stores flows in mongo.

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [23 July 2020 05:55 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/11 "2020-07-23T05:55:06Z")

</div>

I had added the module. But, I didn't understand how to take it forward and use the saveFlows() method to store the flows into mongoDB.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [23 July 2020 06:13 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/12 "2020-07-23T06:13:11Z")

</div>

It's a storage plug-in, you don't have to call any method from within your flow (in fact, you can't), that is done by the runtime. It's an alternative to the filesystem-based storage that is used by default.

Did you read and follow the instructions on how to integrate it? You'd have to modify your settings.js for it to work.

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [23 July 2020 06:25 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/13 "2020-07-23T06:25:40Z")

</div>

I have installed the plugin. I didn't understand the integration part of it as what exactly needs to be edited and how the flows will be stored into my DB. It would be great help if you have any other sample article so I can understand it better.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [23 July 2020 07:03 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/14 "2020-07-23T07:03:13Z")

</div>

Afar from the documentation of the module there's just the doc of the Storage API itself.

[https://nodered.org/docs/api/storage/](https://nodered.org/docs/api/storage/)

The settings.js that you need to modify resides in your Node-RED user directory, usually `.node-red` in your user profile.

---

<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:** [23 July 2020 08:17 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/15 "2020-07-23T08:17:05Z")

</div>

@poojak could you explain why you want to do this, the fact that you are having difficulties with the fundamentals of using a storage plugin makes me wonder whether you misunderstand something.

---

<div class="post-metadata">

**Author:** ![poojak](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@poojak](https://discourse.nodered.org/u/poojak)\
**Post date:** [23 July 2020 09:16 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/16 "2020-07-23T09:16:59Z")

</div>

I want to implement user wise flow storage in database. I have understood the changes are required in settings.js file. What I am not sure is how the saveFlows() works and how am I supposed to add the flows according to the users into mongoDB.

---

<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:** [23 July 2020 09:20 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/17 "2020-07-23T09:20:01Z")

</div>

> [@poojak](#):
>
> how am I supposed to add the flows according to the users into mongoDB.

Node-RED is a single-user system. It runs one set of flows regardless of who has logged in to the editor. The storage layer doesn't know anything about individual users - it just stores the flows being deployed to the runtime.

If you want to just save flows to a database then you can use that plugin you've found and configure it via your settings file exactly as its readme says. That's all you do.

---

<div class="post-metadata">

**Author:** ![teknicus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/teknicus/32/26545_2.png) [@teknicus](https://discourse.nodered.org/u/teknicus)\
**Post date:** [28 July 2020 05:37 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/18 "2020-07-28T05:37:02Z")

</div>

Is there a guide that details how to write a plugin? I'm sure the Documentation is perfect for seasoned JS Devs but I am an amateur and I'm having a bit of trouble finding an example I can refer to.

Thanks

---

<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:** [28 July 2020 07:04 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/19 "2020-07-28T07:04:36Z")

</div>

Oodles of Information [here](https://github.com/adibenmati/node-red-mongo-storage-plugin) and it's a fully working example too - can't get better than that.

---

<div class="post-metadata">

**Author:** ![teknicus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/teknicus/32/26545_2.png) [@teknicus](https://discourse.nodered.org/u/teknicus)\
**Post date:** [28 July 2020 11:47 UTC](https://discourse.nodered.org/t/saving-flows-into-database/30549/20 "2020-07-28T11:47:09Z")

</div>

Thanks for the reference!

Should I add the `var settings { }` code block to settings.js in `~/.node-red/` ?

If yes, That settings file does not have a `var settings { }` code block where I can append the storage module config. Shouldn't there be a line describing the current config? Or should I add one?

Hope I'm not being vague 😐

[Next page](https://discourse.nodered.org/t/saving-flows-into-database/30549.md?page=2)
