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
- It shows objects as empty randomly
- It is generally slow
- It's very unstable
- 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
globals 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?
- Not having the ability to execute it over a network or VM, theoretically you could do X forwarding but it would get too slow and painful