Split function causes Type error

Hi all,
in my flow I receive messages via TCP. The payload is for example 1:::Hello World
Now I want to split the payload into an array where array[0] = 1 and array[1] = Hello World.

I do so by using a function. The input of the function node is connected to the output of the tcp_in.

The function code is:

var IDs = msg.payload.split(":::")

But if I run this I get a "TypeError: msg.payload.split is not a function"

I also tried this:
var smsg = msg.payload
var IDs = smsg.split(":::")

but with the same result

Does anyone have an idea?
Thanks in advance

What type is the input? It may well be a buffer not a string.

you made my day. That was the problem. Thanks a lot

Hi dceejay,
i have a same problem ..I want to show my csv. file as chart.
I used 2 ways: 1. i used a template node(i wrote my data als csv. file in it) -> csv node->function node-> chart node (it works correctly)
2. i want to use file in node (my csv file from PC) -> csv node->function node-> chart node.
if i run my program i get error "payload[i].Data.split is not a function".
Would you have any idea? i attached my flow.
best regrds
samira
flows (1).json (977 Bytes)

Welcome to the forum @Samira05

That probably means that payload[i].Data.split is not a string. Since this question is unrelated to the original question of this thread please start a new thread for it.
First though, if you are a beginner to node-red then I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
Also read carefully the node red docs page Working with Messages which you should find helpful.
If you still need help then start a new thread and there show us what you are feeding into the node generating the error and what is in that node. There is probably no need to post the flow. However, for the future, if you do need to post a flow (or code) then see this post for how to do it - How to share code or flow json

1 Like