in Code

Debugging Node

March 6, 2013

A debugger for me, is a necessity. Going back to the days of print statements to debug seems like something I never want to do. And with debuggers coming a dime a dozen in the Java world, this is really something we must have if switching to run JavaScript on the server. Chrome's debugger is certainly at the top of the list for client side debugging, and with the node-inspector, it's possible to use that same environment to debug any Node based app as well.

Setup is simple, per the instructions on the GitHub repo, first install the package using npm:

npm install -g node-inspector

Then startup your node application in debug mode, using either node or nodemon:

node --debug .


nodemon --debug .

This will start the application on the normal port (usually 3000), and also listen for a debugger on another port (usually 5858). Launch node-inspector in a separate terminal to connect it:


Then open up Chrome and point to your localhost, port 5858: You can add breakpoints and monitor the app as you would normally a frontend application running in the browser. This has been really useful in debugging both the client and server when any issue comes up.

The node-inspector GitHub readme has tons more info, check it out!