# Question about node.send() specifying a message

**URL:** https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143
**Category:** Developing Nodes
**Created:** [12 June 2023 10:36 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143 "2023-06-12T10:36:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Angin](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Angin](https://discourse.nodered.org/u/Angin)
#### Post date: [12 June 2023 10:36 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143/1 "2023-06-12T10:36:23Z")

</div>

In a custom node, I only want to output msg information that meets certain conditions. Other msg information that does not meet the conditions should not output any information when passing through the custom node.

```auto
        node.on("input", function (msg) {
            let str = msg.payload.toString("hex");
            if(str.slice(2, 4) == "01"){
                msg.operinfo = str.slice(24, 26);
            }
            // else{
            // msg.payload = null;
            // }
            node.send({ payload: msg.operinfo });
        });

```

other msg.payload information passing through this node is displayed as undefined. I want undefined information not to be displayed. How do I set this?  
Thank you for your reply.

---

<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: [12 June 2023 10:41 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143/2 "2023-06-12T10:41:37Z")

</div>

> [@Angin](#):
>
> I want undefined information not to be displayed

I assume you mean to be NOT displayed in the debug output?

Then you would `delete` the property.

e.g. `delete msg.payload.a_prop_i_dont_want`

> [@Angin](#):
>
> `node.send({ payload: msg.operinfo });`

This is a bad idea. Many users expect the `msg` to still have properties that they placed in the `msg` to still be there after traveling through your node - for later use downstream in the flow. In fact, what you have written breaks many things (dashboard, HTTP to name a few - since they EXPECT `msg.xyz` to be present).

Far better to simply update the property you care about then return the original `msg` object

e.g.

```auto
msg.payload = {} // whatever
node.send(msg)

```

---

<div class="post-metadata">

### Author: ![Angin](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Angin](https://discourse.nodered.org/u/Angin)
#### Post date: [12 June 2023 11:05 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143/3 "2023-06-12T11:05:00Z")

</div>

Thank you for your quick reply. Yes, I do not want to display undefined debug outputs, as shown in the figure.

![Clipboard 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13d9379c3aa01cd5d3ff9ec65fda8bfbf1da197b.jpeg)

I only want to output "1c", I do not need to output "undefined".

In addition, is delete msg.payload used like this? I tested it and did not get the results I wanted.

```auto
        node.on("input", function (msg) {
            let str = msg.payload.toString("hex");
            if(str.slice(2, 4) == "01"){
                msg.payload = str.slice(24, 26);
            }
            else{
               delete msg.payload;
            }
            node.send(msg);
        });

```

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [12 June 2023 11:15 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143/4 "2023-06-12T11:15:15Z")

</div>

> [@Angin](#):
>
> Thank you for your quick reply. Yes, I do not want to display undefined debug outputs, as shown in the figure.
> 
> ![Clipboard 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13d9379c3aa01cd5d3ff9ec65fda8bfbf1da197b.jpeg)

If your problem is that the entire payload is sometimes undefined:

a) Use a switch node after your function to pass only messages whose payload is not null.  
or b) Only call node.send(msg) when msg.payload is relevant - inside your if() block.

---

<div class="post-metadata">

### Author: ![Angin](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Angin](https://discourse.nodered.org/u/Angin)
#### Post date: [12 June 2023 12:31 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143/5 "2023-06-12T12:31:16Z")

</div>

Thank you very much for your suggestions. I have found a solution:

```auto
        node.on("input", function (msg) {
            let str = msg.payload.toString("hex");
            if(str.slice(2, 4) == "01"){
                msg.payload = str.slice(24, 26);
            node.send(msg);
            }
        });

```

---

<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: [26 June 2023 12:31 UTC](https://discourse.nodered.org/t/question-about-node-send-specifying-a-message/79143/6 "2023-06-26T12:31:50Z")

</div>

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