IRCv3 two messages in one line?

In regards to your code: You do not split the incoming data at all?
As far as I know, twitchs websocket servers always send full messages (no chunking), so a simple data.split("\r\n") should do the trick - after that, iterate over the split parts. Additionally, I suggest using a proper IRC message parser (like the npm package irc-message) instead of things like indexOf, you will be glad you did.

Barry suggested you use tmi.js or similar, for a beginner that is not a bad idea.