# How to Export flows as a message

**URL:** https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559
**Category:** General
**Created:** [14 August 2023 11:22 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559 "2023-08-14T11:22:27Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Light2K95](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Light2K95](https://discourse.nodered.org/u/Light2K95)
#### Post date: [14 August 2023 11:22 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/1 "2023-08-14T11:22:27Z")

</div>

Hi,  
As far as I know Node Red editor saves the current flow(the flow you see when you open the editor) in flows.json file inside C/[username]/.node-red folder by default.

Can I force it to read and display the flow from MongoDB or a different file instead of flows.json when it started?

Alternatively, is there a way to get flows.json(the same json you get when you click export) with a node and send it as a msg.payload?

---

<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: [14 August 2023 11:39 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/2 "2023-08-14T11:39:21Z")

</div>

> [@Light2K95](#):
>
> Can I force it to read and display the flow from MongoDB or a different file instead of flows.json when it started?

Yes, with a storage driver. e.g: [GitHub - adibenmati/node-red-mongo-storage-plugin: Node Red Mongo Storage Plugin](https://github.com/adibenmati/node-red-mongo-storage-plugin)

> [@Light2K95](#):
>
> Alternatively, is there a way to get flows.json(the same json you get when you click export) with a node and send it as a msg.payload?

Since it is a file, on the file system, yes: `file in -> JSON node -> wherever`

---

<div class="post-metadata">

### Author: ![Light2K95](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Light2K95](https://discourse.nodered.org/u/Light2K95)
#### Post date: [14 August 2023 12:27 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/3 "2023-08-14T12:27:25Z")

</div>

Thanks for all your answers so far.

So if I understood correctly, when I add an entry (the flow i want to be displayed) to local mongo, that flow will be displayed when I started Node Red. Instead of the latest one I deployed, right?

---

<div class="post-metadata">

### Author: ![Light2K95](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Light2K95](https://discourse.nodered.org/u/Light2K95)
#### Post date: [15 August 2023 06:33 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/4 "2023-08-15T06:33:56Z")

</div>

I didn't understand what to do with the information in the first link. I'm currently running node red on base directory with "node red.js" command. Should I put the node-red-app provided in the same directory and run Node Red with the command "node node-red-app.js?" after setting up a local Mongo DB?

---

<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: [15 August 2023 06:47 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/5 "2023-08-15T06:47:45Z")

</div>

What parts don't you understand? The link provides all information necessary to get up and running with that plugin.

Can I ask?

Why do you want to save the flows in a mongo database? What is the goal?

---

<div class="post-metadata">

### Author: ![Light2K95](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Light2K95](https://discourse.nodered.org/u/Light2K95)
#### Post date: [15 August 2023 07:30 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/6 "2023-08-15T07:30:17Z")

</div>

From what I understand I need to define my own red.js which I use to run Node Red Editor. I used the one provided in the github link above. And replaced Mongo-URL with my own DB's. Now, before running Node-RED it connects to my db but how do I save the flows file into and load from my MongoDB collection? It still uses the flows file in user directory.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 August 2023 08:07 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/7 "2023-08-15T08:07:38Z")

</div>

You can run [node-red with commandline options](https://nodered.org/docs/getting-started/local#command-line-usage) - which port and which flows file.

You cannot use node-red to read your mongodb get all the flows and run it as such.  
You could get specific flow(s) from mongo and using the [node-red api](https://nodered.org/docs/api/admin/methods/post/flow/) to apply the flow.

> I'm currently running node red on base directory with "node red.js"

Please don't.  
Just use `node-red`, `node-red [options]` or `node-red-start` (depending how you installed it)

---

<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: [15 August 2023 08:43 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/8 "2023-08-15T08:43:05Z")

</div>

> [@Light2K95](#):
>
> From what I understand I need to define my own red.js

Why? Just run node-red.

> [@Light2K95](#):
>
> how do I save the flows file into and load from my MongoDB collection? It still uses the flows file in user directory

Then you are not doing it right.

As the instructions say.

> Firstly, require the module:
> 
> ```
> npm install --save node-red-mongo-storage-plugin
> 
> ```
> 
> Then, in your settings, add:

After adding your settings, start node-red.

* * *

### one more time

> [@Steve-Mcl](#):
>
> Can I ask?
> 
> Why do you want to save the flows in a mongo database? What is the goal?

If you answer this ☝ , we may have alternative solutions or best practices!

---

<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: [15 August 2023 08:47 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/9 "2023-08-15T08:47:14Z")

</div>

> [@bakman2](#):
>
> You cannot use node-red to read your mongodb get all the flows and run it as such.

A [storage plugin](https://nodered.org/docs/api/storage/) such as the mongo one, saves and loads flows directly from a different source. You might be saying the same thing but i read your statement as "it cannot be done"

For example, [FlowForge](https://flowforge.com/) uses this for saving all users flows from all the Node-RED instances into a SQLITE or PostgreSQL DB out of the box (depending on your choices)

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [15 August 2023 08:58 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/10 "2023-08-15T08:58:57Z")

</div>

> [@Steve-Mcl](#):
>
> A [storage plugin](https://nodered.org/docs/api/storage/) such as the mongo one, saves and loads flows directly from a different source. You might be saying the same thing but i read your statement as "it cannot be done"

Ah ok i was not aware of that one, nice!

---

<div class="post-metadata">

### Author: ![Light2K95](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Light2K95](https://discourse.nodered.org/u/Light2K95)
#### Post date: [15 August 2023 11:01 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/11 "2023-08-15T11:01:17Z")

</div>

I want multiple users to work on the same flow, while running different node-red instances simultaneously.

Currently I am running 2 Node-Red instances in different ports locally. When first started, both of them displays the flow I stored in MongoDB. Let's assume there is a flow in json format with 3 nodes in MongoDB. If I remove one of the nodes in instance A via the editor, MongoDB overwrites flows.json collection to have 2 nodes. But, when I refresh my page in instance B, there are still 3 nodes instead of 2. I want the changes I've made in instance A to be reflected on instance B.

---

<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: [15 August 2023 11:13 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/12 "2023-08-15T11:13:52Z")

</div>

This is something you would have to do yourself. Alternatively, you can already do this in FlowForge using devices and / or the pipelines features.

---

<div class="post-metadata">

### Author: ![Light2K95](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@Light2K95](https://discourse.nodered.org/u/Light2K95)
#### Post date: [15 August 2023 13:39 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/13 "2023-08-15T13:39:31Z")

</div>

Thank you Steve. You've been really helpfull.

---

<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 2023 13:39 UTC](https://discourse.nodered.org/t/how-to-export-flows-as-a-message/80559/14 "2023-10-14T13:39:32Z")

</div>

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