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

where would you like to make that call from? From when you click the deploy button, or by an action in your flow? First one means modifying node-red core itself, second means using nodes. That answer makes all the difference in the answer and approach

If you don't answer questions fully and clearly I can't help.

Surely you can see no one has a clue what you are trying to do?

If you want help, please be specific.

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.

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.

Start by reading my earlier post again

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.

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/

1 Like

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

Several, actually.

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

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

1 Like

@dhpatel177 perhaps one of these will help?

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

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

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

Ok, thanks.

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)

Plus, use a Watch node to determine when the flows have changed so you know to update the database.

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

1 Like

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

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);
      });

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.

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. :smile:

2 Likes