Learn WebSocket - Hot Potato missing dependencies in package.json


Just started the Hot Potato project and noticed that the package.json is missing dependencies. I was able to continue on by npm i ws… but I don’t know what other dependencies are needed for this project, if any.

Just thought I would pass this along.

EDIT: If you just npm i ws you will end up with a newer version of WS than what the project is expecting. This isn’t an issue except for when you process your on(‘message’) data it is treated as a buffer. This can be remedied by downgrading your ws module to what is expected of the project (unknown) or converting your data using the toString() method on the data variable.

Personally I chose the later:

wsServer.on('connection', (socket) => {
    socket.on('message', (data, isBinary) => {
        const newData = isBinary ? data : data.toString();

And then I use newData in lieu of data in the rest of the function.

I thought I had an issue as well when I ended up with a Buffer when doing console.log to the server terminal. Turns out I forgot to do JSON.parse(data) when receiving data on the server. It’s perhaps possible that you also had the same issue. I even tried .toString (which worked) before I figured out the real issue I had and then .toString was no longer required.