# Call Node-RED flow from Node.js

**URL:** <https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480>\
**Category:** General\
**Tags:** http-request\
**Created:** [5 June 2022 12:34 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480 "2022-06-05T12:34:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vitaliimarushko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vitaliimarushko/32/62656_2.png) [@vitaliimarushko](https://discourse.nodered.org/u/vitaliimarushko)\
**Post date:** [5 June 2022 12:34 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/1 "2022-06-05T12:34:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [5 June 2022 12:50 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/2 "2022-06-05T12:50:09Z")

</div>

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 😅 )

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43daa796750ef50a7a60f88b12b65caf5ded31c3.png)

---

<div class="post-metadata">

**Author:** ![vitaliimarushko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vitaliimarushko/32/62656_2.png) [@vitaliimarushko](https://discourse.nodered.org/u/vitaliimarushko)\
**Post date:** [5 June 2022 14:17 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/3 "2022-06-05T14:17:08Z")

</div>

Hi @marcus-j-davies !

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

 ![Screenshot (1)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c3053313938e01ef062d108087f0951e68d06f5.png)

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

- [https://jsonplaceholder.typicode.com/todos/1](https://jsonplaceholder.typicode.com/todos/1)

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?

---

<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:** [5 June 2022 14:21 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/4 "2022-06-05T14:21:27Z")

</div>

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.

* * *

> [@vitaliimarushko](#):
>
> Let's say in HTTP IN node I want to call this URL:

Then yes, use the HTTP Request node.

> [@vitaliimarushko](#):
>
> 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?

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)

---

<div class="post-metadata">

**Author:** ![vitaliimarushko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vitaliimarushko/32/62656_2.png) [@vitaliimarushko](https://discourse.nodered.org/u/vitaliimarushko)\
**Post date:** [5 June 2022 14:26 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/5 "2022-06-05T14:26:39Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [5 June 2022 14:29 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/6 "2022-06-05T14:29:18Z")

</div>

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`)

---

<div class="post-metadata">

**Author:** ![vitaliimarushko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vitaliimarushko/32/62656_2.png) [@vitaliimarushko](https://discourse.nodered.org/u/vitaliimarushko)\
**Post date:** [5 June 2022 14:29 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/7 "2022-06-05T14:29:40Z")

</div>

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

---

<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:** [5 June 2022 14:33 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/8 "2022-06-05T14:33:54Z")

</div>

> [@vitaliimarushko](#):
>
> Look, again.

No need.

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

> [@Steve-Mcl](#):
>
> 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)

* * *

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

---

<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:** [5 June 2022 14:37 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/9 "2022-06-05T14:37:54Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fdcbbb868882cdc2c2e76b0166f2db28a35495c7.png)

---

<div class="post-metadata">

**Author:** ![vitaliimarushko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vitaliimarushko/32/62656_2.png) [@vitaliimarushko](https://discourse.nodered.org/u/vitaliimarushko)\
**Post date:** [5 June 2022 14:38 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/10 "2022-06-05T14:38:51Z")

</div>

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

 ![Screenshot (2)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df523a0bc9995573036a2ff330909fbeee3708e9.png)

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!

---

<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:** [19 June 2022 14:39 UTC](https://discourse.nodered.org/t/call-node-red-flow-from-node-js/63480/11 "2022-06-19T14:39:51Z")

</div>

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