Call Node-RED flow from Node.js

Hi!

I built a flow in Node-RED where I make an HTTP request and get some response. Now I need to call this already built flow from Express (Node.js) application and get the calling result inside my server.

If I understood correctly I need to send some message (which one?) to some port (which one?), subscribe (how?) an answer and then receive a response.

  • The Node-RED is locally installed via Docker
  • Node-RED version is 2.2.2
  • Node.js version is 16

Hi @vitaliimarushko

welcome to the forums!

For this (and if I got your question correct) - You can employ the HTTP IN/Response nodes.

So your express application will call a http resource (http in node) http://x.x.x.x:1880/endpoint
This will trigger your flow - and you respond to the http request, with the result from what ever is happening within your flow (i.e a result from another HTTP request for example) - there are no rules with what your http in/response nodes respond with (well within reason :sweat_smile: )

HTTP IN acts as an entry point to trigger the flow - HTTP Response will respond to that request

1 Like

Hi @marcus-j-davies !

Thanks for your answer! But I need more clarification... So, I have prepared this flow:

Let's say in HTTP IN node I want to call this URL:

But I didn't catch what the exact endpoint I need to call from an Express app to run this flow and get the mapped result. Could you explain me, please?

You are using a request - that node is for "requesting" data from an endpoint

If you want an external application to call INTO node-red then you need to use a "HTTP In" node as as detailed in @marcus-j-davies post.


Then yes, use the HTTP Request node.

To achieve that, you will need...

HTTP In (node-red endpoint) --> HTTP Request (call https://jsonplaceholder.typicode.com/todos/1) --> HTTP Response (to reply to the HTTP In caller)

1 Like

@Steve-Mcl I did calling my URL using HTTP IN node, and I used HTTP response node as well as you can see in my diagram. I didn't understand how to call this flow. That was my question...

Look, again. I want to prepare some call to an external API from Node-RED and then just call this Node-RED flow from an Express app. That's all.

On continuation from the above.

bring in a HTTP In Node (set its path to /whatever)
connect this to the start of your flow.

And most importantly bring in a HTTP Response node (set payload to what you want to return) (it must have 'line of-site' with the HTTP in node)

Your express app can then make a call to Node-RED
(say using Axios to http://x.x.x.x:1880/whatever)

This will get the response (what ever you set as the HTTP Response payload)

Sorry, wait. I think I understood my issue...

No need.

I am pretty sure I understood your requirement. Maybe you misunderstood mine?


Let me elaborate further...

  • HTTP In (node-red endpoint) -->
    • This will be called by your express app
  • HTTP Request (call https://jsonplaceholder.typicode.com/todos/1) -->
    • This will call to jsonplaceholder to grab external data
  • HTTP Response (to reply to the HTTP In caller)
    • This will send data back to express

@marcus-j-davies and @Steve-Mcl You both were right! I solved my issue with this schema:

My issue was related to wrong first node! The problem which I faced is that HTTP request and HTTP in nodes look the same.

Thanks to you both!

1 Like

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