How I debug Node.js

Node.js is a server side runtime for Javascript apps. Being a server sided runtime, it doesn’t have a GUI. Therefore it’s abilities to provide an easy to use debugging interface are limited.

Update: Since this was written --inspect support has landed in Node.js. It’s easier to use and doesn’t require installing thirdparty tools. You can find more about it in Node.js debugging Docs.

Why I don’t like Popular Options

There are several ways of debugging Node.js, here are few of the reasons why I don’t like the most popular ones

Builtin CLI debugger

It doesn’t have a GUI of course It’s slow and even hangs at times You have to remember it’s commands Debugging complex problems is nearly impossible if not impossible

It shows ES6 Maps and Sets as null It shows objects as empty randomly It is generally slow It’s very unstable

IDE Debuggers

The IDEs are costy Each has their own UI They are hard to setup They lack advance features

Electron to the rescue

Electron is an open source project by GitHub, it is basically Chromium + Node.js. It has the best of both worlds, node’s require , global s and all the other APIs along with Chromium Dev Tools.

I have written a small wrapper around Electron to allow for quick Node.js debugging. It’s called DeNode, short for Debug Node. You can install it using npm

npm install -g denode

It registers itself as denode bin, it accepts an optional file path of the node module to execute on boot.

denode denode ./index denode ` which browserify `

What’s awesome about this?

You can click and expand on deep nested objects You can profile your apps for memory leaks and CPU time You can set breakpoints on the fly You can update running code from dev tools You can compile your files with babel and debug real source instead of gibberish using sourcemaps Basically, all the awesomeness of Chromium Dev Tools

What’s the side effect?