Debugging Node.js with Google Chrome

Jacopo Daeli
May 25, 2017 · 3 min read

Debugging is the task to identify and remove errors from software applications, and is more than just printing out values in your code. This post describes how to efficiently debug Node.js programs using the latest Google Chrome DevTools.

Why console.log is not the best option?

Debugging tools

Setting up Chrome for Node.js debugging

If you haven’t done it yet, update Google Chrome to the latest version and be sure you are using Node.js 6.4+.

To start debugging, run your Node.js application with the --inspect flag.

$ node --inspect <your_file>.js
Running a Node.js app in Debugging Mode.

Next, ignore the URL starting with “chrome-devtools://” that is displayed in your terminal, but open “about:inspect” in Google Chrome instead.

Inspect with Chrome DevTools.

Finally, click on “Open dedicated DevTools for Node” to start debugging your application’s code.

Developer Tools for Node.

Moreover, the official documentation on debugging Node.js App offers a detailed list all the other inspector tool and client alternatives.

Chrome DevTools in action

Simple Express application.

Let’s run it with the --inspect flag and open the dedicated DevTools for Node as explained before.

At this point, you will have access to all the features you may be already familiar with: breakpoints, source map for transpiled code, heap snapshot inspection, allocation profiling, JavaScript values hot-swapping, etc.

Using Breakpoints to debug an Express application.

In particular, as you can see in the images below, you can insert breakpoints to stop the execution of your program, inspect and “hot-swapping” the values of the variables.

JavaScript values hot-swapping (1).
JavaScript values hot-swapping (2).

Another awesome thing in using Chrome as a debugging tool is that you can debug both your front-end and back-end JavaScript code with the same interface 🚀.

If you have any questions on this or updates, please reach out to me on Twitter at @JacopoDaeli.

Node.js Collection

Community-curated content for the millions of Node.js users.

Jacopo Daeli

Written by

I’m a Computer Scientist, Software Engineer and Hacker, passionate about web technologies with a vocation for writing beautiful and clean code.

Node.js Collection

Community-curated content for the millions of Node.js users.