I am following the directions here: https://github.com/node-inspector/node-inspector
Pretty simple. npm install node-inspector
. In one shell run node-inspector
and in another run node --debug app.js
. Shell spits out an localhost address with specific port for the debugger. Open that address in a browser — it loads your code. From there add breakpoints, debug network, etc..
But this does not work. The following message endlessly logs in my shell:
Failed to open socket on port 5858, waiting 1000 ms before retrying
..and no connection is made.
So my question is has anyone had this problem and successfully found a solution. Would love to get this working, would be super useful. My only experience in server-side debuggers is Ruby's Byebug
which was a piece of cake to set up.
The message you see is printed because there is another process listening on port 5858. Either a different application, or simply another instance of a node process under the debugger.
An update based on comments below this answer
If your application is running in a cluster mode via Node.js core module "cluster", then you end up with multiple worker processes, where each of them is trying to listen on port 5858.
Node Inspector cannot debug multiple worker processes at the same time. You have to pick one process and enable the debugger in that process only. When you start the app via node --debug
, all processes try to enable the debugger, therefore you cannot use this command.
Instead, you have to:
kill -1 <pid>
on UNIX, or use node debug -p <pid>
that works on all platforms. Don't forget to exit node debug
before proceeding further.My answer is based on the following blog post: https://strongloop.com/strongblog/whats-new-nodejs-v0-12-debugging-clusters/, check it out for more details.