# How to modify node-red deploy operation to save flow to database

**URL:** <https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568>\
**Category:** Core Development\
**Created:** [13 May 2020 05:37 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568 "2020-05-13T05:37:31Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![dhpatel177](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dhpatel177/32/39248_2.png) [@dhpatel177](https://discourse.nodered.org/u/dhpatel177)\
**Post date:** [13 May 2020 08:37 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/21 "2020-05-13T08:37:37Z")

</div>

when click on deploy button i want to save the flow to my database and that's why in between of that i want to make a call to my api.

---

<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:** [13 May 2020 08:39 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/22 "2020-05-13T08:39:12Z")

</div>

Right so in all the posts you have made, this is the first time you have said that.

This topic belongs in core development.

I will modify the title and move it then someone from core team might be able to assist.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [13 May 2020 08:42 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/23 "2020-05-13T08:42:43Z")

</div>

Start by reading my earlier post again

> [@How to modify node-red deploy operation to save flow to database](https://discourse.nodered.org/t/call-external-api-from-js-file/26568/16):
>
> Darshan, the function that is called when you press the deploy button lives in the runtime of node-red: this is server code, on nodejs. The code you have added to it uses jquery. Jquery is a framework for interacting with DOM structures in the browser, meaning it is clientside code. If you want to do this, start by learning the difference between clientside and serverside, and learn some nodejs basics. Next, figure out a way to call http apis from nodejs. The error you’re seeing is the call to…

The error you see is caused by trying to write jquery/clientside code to call an api, on runtime level which uses nodejs/serverside JavaScript. Both types of JavaScript but completely different in use. Make sure you understand the difference, and figure out a way to make an http request from nodejs.

---

<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:** [13 May 2020 08:43 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/24 "2020-05-13T08:43:05Z")

</div>

Do you want to load/save your flows to a database in general?

Maybe the Storage API is what you're looking for. You can implement a custom backend, without involving flow files in the first place.

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

---

<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:** [13 May 2020 08:47 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/25 "2020-05-13T08:47:42Z")

</div>

@kuema, do you know of any custom storage backend that saves to database already implemented? Perhaps it's already done?

---

<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:** [13 May 2020 08:51 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/26 "2020-05-13T08:51:52Z")

</div>

Several, actually.

[https://www.npmjs.com/search?q=node-red%20storage](https://www.npmjs.com/search?q=node-red%20storage)

EDIT: Some of these are nodes, not storage backends!

---

<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:** [13 May 2020 08:53 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/27 "2020-05-13T08:53:47Z")

</div>

> [@kuema](#):
>
> [node-red storage - npm search](https://www.npmjs.com/search?q=node-red%20storage)

@dhpatel177 perhaps one of these will help?

---

<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:** [13 May 2020 08:55 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/28 "2020-05-13T08:55:53Z")

</div>

Here's one for MongoDB, for example: [https://www.npmjs.com/package/node-red-mongo-storage-plugin](https://www.npmjs.com/package/node-red-mongo-storage-plugin)

---

<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:** [13 May 2020 09:10 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/29 "2020-05-13T09:10:56Z")

</div>

Can I ask why you want to save it to a database?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [13 May 2020 09:22 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/30 "2020-05-13T09:22:59Z")

</div>

I think the goal is to get the multi-user approach mentioned in this very first post, each user getting their own flows:

> [@Node red for Individual User](https://discourse.nodered.org/t/node-red-for-individual-user/26234):
>
> Hello, In my application i have a requirement like for an individual there should be individual flows should be saved on node red. For example if i have created some flow and again when i came to my node site than the same flow should be shown and like wise for other users they should be able to see their flows. Is it possible?

---

<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:** [13 May 2020 09:27 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/31 "2020-05-13T09:27:25Z")

</div>

Ok, thanks.

---

<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:** [13 May 2020 09:46 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/32 "2020-05-13T09:46:15Z")

</div>

Why not use the file node to read flows.json put it through a change node and extract the tab you are looking for and store that in the database. (Roughly speaking)

---

<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:** [13 May 2020 09:52 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/33 "2020-05-13T09:52:57Z")

</div>

Plus, use a Watch node to determine when the flows have changed so you know to update the 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:** [13 May 2020 11:24 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/34 "2020-05-13T11:24:28Z")

</div>

no - the correct way is as @kuema pointed out... to write your own Storage plugin to the provided storage API.

---

<div class="post-metadata">

**Author:** ![dhpatel177](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dhpatel177/32/39248_2.png) [@dhpatel177](https://discourse.nodered.org/u/dhpatel177)\
**Post date:** [13 May 2020 12:00 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/35 "2020-05-13T12:00:44Z")

</div>

Guys just found one way to call to external api using..............Thanks for your efforts @afelix @Steve-Mcl @kuema @Colin @bakman2

> **[axios](https://www.npmjs.com/package/axios)**
>
> Promise based HTTP client for the browser and node.js

---

<div class="post-metadata">

**Author:** ![dhpatel177](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dhpatel177/32/39248_2.png) [@dhpatel177](https://discourse.nodered.org/u/dhpatel177)\
**Post date:** [13 May 2020 12:28 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/36 "2020-05-13T12:28:05Z")

</div>

## npm install axios

## add in packag.json - "axios": "0.19.2"

## In js file :- var axios = require( "axios" );

```
    axios.post('http://localhost:65305/api/v1/flow', {
        flowName: "test 2",
        flowData: "test 4",
        userId: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        solutionId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
```

---

<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:** [13 May 2020 12:35 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/37 "2020-05-13T12:35:50Z")

</div>

> [@dceejay](#):
>
> the correct way is as @kuema pointed out... to write your own Storage plugin

That is the correct way, by one definition of the word correct, but as many people would not have the knowledge to do that an alternative crude method may be more appropriate.

---

<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:** [13 May 2020 12:39 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/38 "2020-05-13T12:39:48Z")

</div>

I'd rather implement a well-documented API than poking and muddling around in the core code I know nothing about, and possible break other things along the way. 😄

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [13 May 2020 12:41 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/39 "2020-05-13T12:41:25Z")

</div>

I think it depends on the use case. The first created topic mentions this as a requirement for an application/project. If this would be rolled out, the environment in which it happens might play a role too. Some go for a custom version of node-RED to solve specific domain level issues they run into or embed requirements for their own use case. Others can do with a generic solution through a storage plugin that integrates with the unmodified core. Making modifications to the core means you can’t easily upgrade without merging all upstream changes back into your fork, assuming you make a fork first. Whilst through a storage plugin unless there are breaking changes you can easily update. But if you’ve changes needed beyond what a storage plugin, or say a middleware elsewhere, can solve, sometimes forking and modifying the core is your best option.

---

<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:** [13 May 2020 12:41 UTC](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/40 "2020-05-13T12:41:28Z")

</div>

Isnt this just gonna get broken everytime node-red is updated?

I feel it would be better to use the Storage API mechanism @kuema pointed out [here](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568/24)

[Previous page](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568.md?page=1)

[Next page](https://discourse.nodered.org/t/how-to-modify-node-red-deploy-operation-to-save-flow-to-database/26568.md?page=3)
