Node Inspector for Debugging Node.js application
Jul 21, 2012
Suresh Vasudev
2 minute read

Bugs are often a part of software development and as developers we often need good tools to debug and fix these bugs effeciently. Node Inspector is one of the power debugging tools available for node.js.

Let us install this debugger globally so it will be available to all nodejs application in the system.

npm install -g node-inspector

To demonstrate the usage of debugger let us create a simple Express based web application.

express debugeg
cd debueg
npm install
node app.js

We will now able to view the application via http://locahost:3000

Once we make sure that the default application is working, restart it in debug mode as mentioned below.

node --debug-brk app.js

Node Inspector will put a breakpoint in the first line of the application, when we use –debug-brk. On successful startup of the application in debug mode, node will display the following message “*debugger listening on port 5858*”

Now start the Node Inspector by typing the command “node-inspector”. System will display the following message on successful startup of node insepector as

*info - started . visit to start debugging*

Now open the above URL : in Chrome. The URL will work only in WebKit JS debugger supported browsers. The node inspector will display the application code in a debug window where we can step through the code and understand the behaviour of the application.


Advantages of Node Inspector

  1. Help to debug the code and fix the issues
  2. Help to understand the underlying node.js code and its functioning
  3. Reading the code can be more interactive using node-inspector debug window.

We can also use the V8 debugger to debug the application, which we will be done through command terminal window. However it is the developer comfort to decide which tool to use.