Tips for debugging multiple Node.js processes

January 31, 2016

Here are some quick tips for debugging multiple node.js. I had some trouble debugging multiple processes early on, but I realized a couple things I want to note. Hopefully they can help!

Debugging mulitple node processes

I like running node processes with the --debug flag. I know there are other ways (like using node-debug app.js) but I found doing this was best for dealing with many processes, mostly because you can still use node-inspector or terminal without much issue. If you need extra info here might be a good spot to start.

It should look something like this:

node --debug file_to_debug.js

At this point you can debug via node-inspector or terminal.

Using Node-inspector:

Node-inspector can attach itself to different processes if needed by changing the port. All you have to do is run node-inspector in another terminal window then go to<debugging port>

You can then change the debugging port to inspect different processes. Start from port 5858 and move 1 up for every process.

If you want to know what process you’re debugging you can find out by using adding a watch expression

Using Terminal:

Open another terminal window and run:

node debug localhost:<debugging port>

Then you can basic terminal commands once debugging:
repl - Open debugger’s repl for evaluation in debugging script’s context
cont, c - Continue execution on a break point (debugger;)
next, n - Step next
step, s - Step in
out, o - Step out
pause - Pause running code (like pause button in Developer Tools)

You can find all of the terminal commands at The Node.js Documentation for Debugger

Happy debugging!