# How can I add two input port in the node I created

**URL:** <https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214>\
**Category:** General\
**Created:** [2 August 2021 13:36 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214 "2021-08-02T13:36:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ma\_23](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@ma\_23](https://discourse.nodered.org/u/ma_23)\
**Post date:** [2 August 2021 13:36 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/1 "2021-08-02T13:36:53Z")

</div>

I need to have two input for one node I created .Yet it only allows to have one input . Is there a way to do that ?

---

<div class="post-metadata">

**Author:** ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)\
**Post date:** [2 August 2021 13:54 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/2 "2021-08-02T13:54:22Z")

</div>

Can't you just pass a `msg` object which contains all the needed information into your node?

Something like ..

```auto
msg.input1 = "input 1"
msg.input2 = "input 2"

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 August 2021 14:18 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/3 "2021-08-02T14:18:19Z")

</div>

Nodes are only allowed to have one input

---

<div class="post-metadata">

**Author:** ![ma\_23](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@ma\_23](https://discourse.nodered.org/u/ma_23)\
**Post date:** [2 August 2021 14:42 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/4 "2021-08-02T14:42:07Z")

</div>

I don't think so because I just want to add a second port without knowing what it will do or what kind of input it will be passed

---

<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:** [2 August 2021 14:49 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/5 "2021-08-02T14:49:38Z")

</div>

Everyone else manages. I don't see your issue.

So if you are building your own custom node, simply document how the input data should be formatted.

The bottom line is, node-red doesn't support multiple inputs and likely never will.

---

<div class="post-metadata">

**Author:** ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)\
**Post date:** [2 August 2021 14:53 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/6 "2021-08-02T14:53:39Z")

</div>

Can you share some details about your node? Maybe the forum can provide a solution which is acceptable.

---

<div class="post-metadata">

**Author:** ![ma\_23](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@ma\_23](https://discourse.nodered.org/u/ma_23)\
**Post date:** [2 August 2021 20:52 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/7 "2021-08-02T20:52:59Z")

</div>

Ok I will explain you more what I need:  
I created a node for machine learning which is train model and this node need two inputs: one for the model and another for the dataset

---

<div class="post-metadata">

**Author:** ![ma\_23](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@ma\_23](https://discourse.nodered.org/u/ma_23)\
**Post date:** [2 August 2021 20:53 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/8 "2021-08-02T20:53:15Z")

</div>

I created a node for machine learning which is train model and this node need two inputs: one for the model and another for the dataset

---

<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:** [2 August 2021 20:53 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/9 "2021-08-02T20:53:53Z")

</div>

Do you expect these to be sent into your node at the same time or independently?

### If you expect the inputs at separate times, then you could use a `topic` to identify the payload

e.g.

```json
{
  topic: "model"
  payload: { /* model data */ } 
}

```

and

```json
{
  topic: "dataset"
  payload: { /* dataset */ } 
}

```

  

### If you expect the inputs at the same time simply send them together in one object

```json
{
  topic: "dataset"
  payload: {
    model: { /* model data */ },
    dataset: { /* dataset data */ },
  }  
}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 August 2021 21:35 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/10 "2021-08-02T21:35:16Z")

</div>

Even if you could have two inputs they won’t arrive at the same time.

With two msgs, you could have a `join` node create one msg, containing all the information (as @Steve-Mcl showed), that would go into your custom node.

---

<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:** [1 October 2021 21:35 UTC](https://discourse.nodered.org/t/how-can-i-add-two-input-port-in-the-node-i-created/49214/11 "2021-10-01T21:35:43Z")

</div>

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