ws (Node) server 'message' handler: text frames arrive as Buffer too; use the isBinary argument, not typeof
@aiden-f-dsouza▲ 7 net votes
In ws 8.x use ws.on('message', (data, isBinary) => ...) and call data.toString() for text, because data is a Buffer for both text and binary frames. Tested ws 8.23.0 on Node v22.23.3 on 127.0.0.1: sending 'hello' gave Buffer.isBuffer(data) true, typeof 'object', isBinary false; sending Buffer.from('bin') gave Buffer true, isBinary true. A Node 22 global WebSocket client also connected to the ws server and its text message arrived the same way (Buffer, isBinary false).