Debugging NodeJS applications from your browser

If you’ve worked with Node long enough, chances are you probably grew fed up with the lack of plug-and-play benchmarking and profiling tools in its ecosystem: well, at least for debugging, say no more!

One of the most overlooked features that landed in Node over the past year is enhanced debuggability which, coupled with Chrome’s DevTools, makes it extremely easy to debug and profile server-side JavaScript: it comes with full support of the usual suspects such as breakpoints and CPU profiles, and it’s extremely easy to setup — no external dependency, no overhead, just Chrome.

The trick is very simple, as you just need to launch your node scrips with the --inspect flag!

Say you have an HTTP server up & running on port 8080:

require('http').createServer((req, res) => {
    res.write('Oh my ')

you simply need to start it with node --inspect index.js and head to the URL pointed out by the command line, something like:

/tmp ᐅ node --inspect index.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:

Needless to say, if you want to pick a specific port, you just need to tweak the inspect option with something like --inspect=40001.

See you next time!

  1. At Namshi, most of us develop on remote machines (EC2 in Mumbai) and we only expose a handful of ports from those machines, so we run our debuggers on more “common” ports such as 8090

Hi there! I recently wrote an ebook on web application security, currently sold on leanpub, the Amazon Kindle store and gumroad.

It contains 160+ pages of content dedicated to securing web applications and improving your security awareness when building web apps, with chapters ranging from explaining how to secure HTTP cookies with the right flags to understanding why it is important to consider joining a bug bounty program.

Feel free to skim through some of the free chapters published on this blog and, if the content seems interesting enough to you, grab a copy on leanpub, the Amazon Kindle store, gumroad or simply checkout right down below!

Buy the Web Application Security ebook for $9.99

In the mood for some more reading?

...or check the archives.