Chapter 18

Debugging Modules and Applications


  • Formatting and outputting variables
  • Using variable interpolation
  • Using the Node debugger
  • Using a visual Node debugger

Building functional software is not a trivial task. Dividing your application code into small modules and testing each one thoroughly can help, but you’re still bound to find problems. If you find yourself in a situation where you need to inspect the inner workings of your Node application or module code, several tools can help. This chapter covers several of those debugging tools – console.log, Node’s built-in debugger, and Node Inspector.


Node has some global objects that you can use without requiring them explicitly. One of them is the console object, which enables you to output formatted strings.

The simplest debugging tool at your disposal is console.log. This function call does two things – it serializes and concatenates your objects into a string and outputs the result to the standard output stream. You can use it to inspect objects like this:

var obj = {a: 1, b: 2};

This last snippet prints the following:

{ a: 1, b: 2 }

This simple example passes in an object that is translated into a literal string representation. You can pass in any type of object, and console.log will inspect its properties and values.

NOTE Actually, console.log does not do any formatting. All the formatting is done by the util.format function. Whatever arguments you pass in to ...

Get Professional Node.js: Building Javascript Based Scalable Software now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.