# Why don't Node-RED nodes allow multiple inputs?

**URL:** <https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973>\
**Category:** FAQs\
**Created:** [10 May 2019 05:40 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973 "2019-05-10T05:40:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrotherCreamy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brothercreamy/32/8191_2.png) [@BrotherCreamy](https://discourse.nodered.org/u/BrotherCreamy)\
**Post date:** [10 May 2019 05:40 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/1 "2019-05-10T05:40:54Z")

</div>

For clarity:  
I'm not asking _ **how** _ to implement multiple inputs to a function, I already know the workarounds. I want to know _ **why** _ Node-RED developers would inhibit such a functionality.

It seems so obvious and natural to allow multiple inputs to a function.

For example: say I want to create a function `Divide(dividend, divisor)` that returns `dividend` divided by `divisor`. In JavaScript this would be:

```
function Divide(dividend, divisor) {
  return dividend / divisor
}

```

With Node-RED, the same function looks like this:

```
var dividend = 0
var divisor = 0

if (msg.topic == 'dividend')
{
    dividend = msg.payload
    context.set('dividend', dividend)
    divisor = context.get('divisor')
}
else if (msg.topic == 'divisor')
{
    divisor = msg.payload
    context.set('divisor', divisor)
    dividend = context.get('dividend')
}

return {payload:(dividend/divisor)};

```

(In addition, I have to assign topics 'divisor' and 'dividend' to the inputs so that the function doesn't get confused between which is which)

I understand that this is because Node-RED is message-based rather than functional, but I can't really be the only person who thinks this is an absurd amount of effort for such a simple task, right?

I understand that I could avoid using `context` if I used a `join` node and wait to receive two messages, but I want my function to update upon any change of input, since otherwise the function's output would be out-of-date until the second message is received.

I would imagine if developers implemented a multiple input functionality, the function would run upon receiving a new message on any of its inputs, and since messages on any given wire are retained by default until the next message is sent, you wouldn't have to worry about implementing retention using `context`.

Also, if you were able to name function inputs, you wouldn't have to worry about sorting the inputs by topic and explicitly assigning a topic to each of your inputs to support this.

Is this a deficiency of Node-RED or am I completely missing the point?

---

<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:** [10 May 2019 06:16 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/2 "2019-05-10T06:16:19Z")

</div>

Think about this - how would you synchronise the triggering of inputs? So let's say you use 2 change nodes to set parameter X & Y then triggered by same item, this would be no different from setting `msg.X` and `msg.Y` then sending 1 message to the function. However, the singular input guarantees both function parameters are sent together.

I'm not saying their isn't a place for multiple inputs I just think it may introduce more problems than solves - or - indeed may solve a different problem (like multiple functions)

---

<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:** [10 May 2019 06:19 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/3 "2019-05-10T06:19:35Z")

</div>

> [@BrotherCreamy](#):
>
> but I want my function to update upon any change of input

But you still need them both in order to complete the function, so join is the better choice.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [10 May 2019 06:38 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/4 "2019-05-10T06:38:12Z")

</div>

As non-developer, you've got a point that combining two messages takes a fair bit of work

But I think its just one of the downsides of the Node-RED programming paradigm (all languages have them)

However, the upsides of the Node-RED flow-based processing, make it easy to do stuff that would be a lot of work in other languages.

I'm using Node-RED across 6 computers with hundreds of flows and only in a few of them do I have to deal with processing 2 inputs in one function node so I think its a small problem

My solution is to set flow variables so that I don't need code inside a function to handle the issue

```auto
[{"id":"dc810972.eae048","type":"inject","z":"6f615236.c9bffc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":80,"wires":[["713189b4.385b28"]]},{"id":"1fa86359.711b4d","type":"inject","z":"6f615236.c9bffc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":160,"wires":[["e4b18db.44e5e7"]]},{"id":"713189b4.385b28","type":"change","z":"6f615236.c9bffc","name":"","rules":[{"t":"set","p":"dividend","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":80,"wires":[["c4f32506.acdf68"]]},{"id":"e4b18db.44e5e7","type":"change","z":"6f615236.c9bffc","name":"","rules":[{"t":"set","p":"divisor","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":160,"wires":[["c4f32506.acdf68"]]},{"id":"c4f32506.acdf68","type":"function","z":"6f615236.c9bffc","name":"","func":"\nreturn {payload:(flow.get('dividend')/flow.get('divisor'))};","outputs":1,"noerr":0,"x":570,"y":120,"wires":[["e5a1aa80.bc9678"]]},{"id":"e5a1aa80.bc9678","type":"debug","z":"6f615236.c9bffc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":120,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/17203cbbb5d059f8f44bf4e68ba3f7ad341df7e5.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e2da1ffac9b347511ad65f15ce32c14971390fee.png)

---

<div class="post-metadata">

**Author:** ![BrotherCreamy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brothercreamy/32/8191_2.png) [@BrotherCreamy](https://discourse.nodered.org/u/BrotherCreamy)\
**Post date:** [10 May 2019 06:53 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/5 "2019-05-10T06:53:42Z")

</div>

Say that I receive messages from multiple different sensors only when their respective inputs change by 1 LSB.

I want to update the result every time an input is updated, so that I always have the correct result. Also, since there is no order to the messages, waiting for two messages to be received would result in unpredictable and slow behaviour. For example, if sensor A is updating its output on average 5 times a second, and sensor B is updating its output on average once every minute, using a `join` would mean my calculation would only update once a minute instead of 5 times a second.

---

<div class="post-metadata">

**Author:** ![BrotherCreamy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brothercreamy/32/8191_2.png) [@BrotherCreamy](https://discourse.nodered.org/u/BrotherCreamy)\
**Post date:** [10 May 2019 06:57 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/6 "2019-05-10T06:57:00Z")

</div>

Hi cymplecy,  
I like your implementation, however it means that every time I use a new Divide function node within the same flow, I will need to create new flow variables each time.

I think if I'm just using the function node once, then I will do it your way. If I need to reuse it multiple times in the same flow, I'd probably stick with doing it my way.

Thanks!

---

<div class="post-metadata">

**Author:** ![BrotherCreamy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brothercreamy/32/8191_2.png) [@BrotherCreamy](https://discourse.nodered.org/u/BrotherCreamy)\
**Post date:** [10 May 2019 06:57 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/7 "2019-05-10T06:57:37Z")

</div>

Thanks for your reply Steve,

Please see my reply to bakman2

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [10 May 2019 06:57 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/8 "2019-05-10T06:57:58Z")

</div>

> [@BrotherCreamy](#):
>
> For example, if sensor A is updating its output on average 5 times a second, and sensor B is updating its output on average once every minute, using a `join` would mean my calculation would only update once a minute instead of 5 times a second.

You can configure the Join node to join messages from separate topics into a single Object _and_ send that updated object whenever another message arrives. So this scenario you highlight is already handled.

---

<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:** [10 May 2019 07:16 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/9 "2019-05-10T07:16:58Z")

</div>

You don't have to. The flow variable is used for the flow, so you don't even have to connect it, just update when a new value arrives.

 ![39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2f1c5ae970ac9cdc63b543ce7dc7de715d2a9d96.jpeg)

---

<div class="post-metadata">

**Author:** ![BrotherCreamy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brothercreamy/32/8191_2.png) [@BrotherCreamy](https://discourse.nodered.org/u/BrotherCreamy)\
**Post date:** [10 May 2019 07:34 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/10 "2019-05-10T07:34:17Z")

</div>

Thanks knolleary,

Right I just figured it out.

I didn't notice the "and every subsequent message" tickbox in the `join` node.  
Now it's a lot simpler.

**FOR THOSE WONDERING ABOUT HOW TO IMPLEMENT A MULTIPLE INPUT FUNCTION ON NODE-RED, THE ANSWER IS BELOW:**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8425a421988a03a65095b02e62ba03185a7b74fa.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0053628b544f3d9b9c16658049385e8725f07793.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/926653463cbf1958f1e37d2c2993e3de4ba032de.png)

Thanks a lot!

Cheers,  
David

---

<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:** [28 August 2019 18:34 UTC](https://discourse.nodered.org/t/why-dont-node-red-nodes-allow-multiple-inputs/10973/11 "2019-08-28T18:34:56Z")

</div>


