I'm using the Google Chrome Developer Tools plugin for Eclipse to debug my Node.js server. This server uses Socket.io for the websocket connection between my web client and the server. The problem es when I set a breakpoint in my server and start stepping through the code. The client soon decides the server isn't there anymore because there's no longer a heartbeat or any munication, so it disconnects. Meanwhile, as I'm stepping through, my code tries to do something with the socket and then it dies since the socket is now shutdown. It makes it a bit tricky trying to debug like this.
So the question is, how can I debug a server like this with an open websocket connection and not close the connection? I don't know that there's a good solution, but I thought I'd put it out there and see if anyone has a genius idea.
I'm using the Google Chrome Developer Tools plugin for Eclipse to debug my Node.js server. This server uses Socket.io for the websocket connection between my web client and the server. The problem es when I set a breakpoint in my server and start stepping through the code. The client soon decides the server isn't there anymore because there's no longer a heartbeat or any munication, so it disconnects. Meanwhile, as I'm stepping through, my code tries to do something with the socket and then it dies since the socket is now shutdown. It makes it a bit tricky trying to debug like this.
So the question is, how can I debug a server like this with an open websocket connection and not close the connection? I don't know that there's a good solution, but I thought I'd put it out there and see if anyone has a genius idea.
Share Improve this question asked Oct 11, 2012 at 20:00 Justin WarkentinJustin Warkentin 10.2k4 gold badges37 silver badges35 bronze badges4 Answers
Reset to default 7After doing more research I discovered a couple different projects that looked hopeful, namely 'node-inspector' and 'node-codein'. However, node-inspector doesn't work with the latest versions of node, and node-codein has a lot of bugs. Also, neither is really maintained and they both only work with Chrome. So, I wrote my own solution, called Node Monkey, which is really simple to use and it works with Firefox or Chrome. It simply captures things logged to the console in your Node app and redirects that output to the browser console. You can install it by running:
npm install node-monkey
Even if it sounds a littly nasty and stone-aged, but in this cases (actually debugging a client->server environment) I regulary use standard outputs on the server-side, just like console.log()
and console.debug
.
If you need to debug your client-side script, you could do just the same, if you don't want to lose the server connection. I actually don't see any other way around it beside you re-configure socket.IO's heartbeat timeouts fundamentally higher.
I know this is ages later, but another option I found that ended up being perfect for a quick socket.io sanity check is socket-io-tester.
I mention it here since this answer was the first result on google and it took me a little more digging to find the tool.
for this you can follow official documentation of socket.io
https://socket.io/docs/v3/logging-and-debugging/index.html
In my case, I did this in my package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "DEBUG=engine,socket.io* nodemon src/server.js"},
I hope it will help you or feel free to ask me in case you have any doubt