Debugging NodeJS application in Windows

Debugging NodeJS application in Windows

This will be the first post in the category Black book, which will stand for common errors that I make and do not want to repeat. This idea came from the great book on IT management Making Things Happen.

So, debugging the Node application – usually after the NodeJS is setup, developers start working on theirs NodeJS projects using the standard console output. For example, I want to control what number I get after the function call

function getTheNumber(inputNumber) {
  return (inputNumber * 5);
console.log('Result: ' + getTheNumber(10));

The output will look like this

C:\Users\alexshumilov\blog\test>node test.js

But what if you need to debug some complex logic, with all pros and cons of the JavaScript? What if you need the debugger like in desktop application developement IDE’s, with breakpoints, scope variables view etc.? The node-inspector will help you out in this one.

First we need to install it using the NPM package manager

npm install -g node-inspector

Then we open separate console window and execute

C:\Users\alexshumilov>node-inspector &
Node Inspector v0.12.3
Visit to start debugging.

Then in another console window we actually launch our code in debugging mode

C:\Users\alexshumilov\blog\test>node --debug-brk test.js
Debugger listening on port 5858

Visit the provided link and you will get

node-inspector window with the test script

  • Александр

    It is a stroke of genius