# Node.send( ) stuck with loop

**URL:** <https://discourse.nodered.org/t/node-send-stuck-with-loop/32394>\
**Category:** General\
**Created:** [3 September 2020 10:35 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394 "2020-09-03T10:35:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 10:35 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/1 "2020-09-03T10:35:25Z")

</div>

Given:  
`msg.payload = 0`  
and  
msg.menu exists thus:

```auto
{"1":"Show clock/time","2":"Show alarms","3":"Edit time/date","4":"Edit alarm/s","5":"Alarm run time"}

```

I have done things similar and done things like this before.  
They work.  
I'm not getting this.

So I have a `function` node with this code:

```auto
var starting = parseInt(msg.payload);
var ending = starting + 2 // set to 2 for now. Just to prove the code set at 2

//node.warn("Starting " + starting)
//node.warn("Ending " + ending)
//node.warn(msg.menu)

if (starting < ending)
{
    //
    pop()
}
return;

function pop() {
    node.warn("Loop" + starting);
    node.warn("Ending " + ending);
    node.send(msg.menu[starting]);
    starting +=1;
    if (starting < ending){
        pop()
    }
}

```

Yeah, full of `node.warn()` stuff.

I'm not getting why the `node.send(msg.menu[starting]);` isn't working.

When the `node.warn()` line is active I see the structure.

And I am getting this as an error:  
`Function tried to send a message of type string`

---

<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:** [3 September 2020 10:42 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/2 "2020-09-03T10:42:05Z")

</div>

`node.send` needs to send an object, unless you configured the debug node to display something else. You are not sending an object, but a number eg. `node.send({menu:starting})` - which in turn will output `{menu:x}`

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 10:43 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/3 "2020-09-03T10:43:34Z")

</div>

Ideally, it should send one (two) of the entries.

Yes, I realised that `0` is not a good starting point.

So, that aside.... I am not getting why it is complaining.

I really am not getting these _types_.  
(Some one shoot me)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 10:46 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/4 "2020-09-03T10:46:14Z")

</div>

Trying to de-construct it as much as I can:

```auto
var x = msg.menu[1];
node.warn("X " + x);
node.send(x);
var y = msg.menu[2];
node.warn("Y " + y);
node.send(y);

```

I get the `X` and `Y` messages shown to me.

So..... I'm not seeing the elephant.

# Oh! So it has to be part of a message?

eg: `node.send(msg.something)`

That doesn't _hold water_ because I tried to send `msg.menu[1]` and it didn't like it either.

---

<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:** [3 September 2020 10:50 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/5 "2020-09-03T10:50:09Z")

</div>

You have to send a message **Object**.

You cannot send just a String.

So instead of doing

```auto
node.send(msg.menu[1]);

```

you need to wrap it in a message object:

```auto
node.send( { payload: msg.menu[1] })
```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 10:51 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/6 "2020-09-03T10:51:20Z")

</div>

One day I may remember all these structures.

Alas until then, sorry folks.

Nick: Thanks.

---

<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:** [17 September 2020 10:51 UTC](https://discourse.nodered.org/t/node-send-stuck-with-loop/32394/7 "2020-09-17T10:51:32Z")

</div>

Closed on 17 September 2020 10:51 UTC

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