Debugging Node.js with Chrome DevTools

New support for Node.js debuggability landed in Node.js master in May. You can see it in action in the DevTools Google I/O talk. Or you can try it out yourself, right now. Let’s go…

(post updated August 2016)

Here’s how to get up and running:

  1. Download and install the current version of node.

A nightly build was previously required, but support is in node as of v6.3.0.

You can install manually, use nvm to install the latest: nvm install node, or even use node-nightly to get a fresh nightly build.

3. Run it with the --inspect flag

node --inspect index.js

You can also break on the first statement of the script with --debug-brk.

node --inspect --debug-brk index.js

4. Open the provided URL

You’ll get a url starting with “chrome-devtools://..” to copy/paste into Chrome. After dropping it in, you’ll have all the Chrome DevTools features you’re used to:

  • Complete breakpoint debugging, stepping w/ blackboxing
  • Source maps for transpiled code
  • LiveEdit: JavaScript hot-swap evaluation w/ V8
  • Console evaluation with ES6 feature/object support and custom object formatting
  • Sampling JavaScript profiler w/ flamechart
  • Heap snapshot inspection, heap allocation timeline, allocation profiling
  • Asynchronous stacks for native promises

Enjoy.