Node has a built in debugger, which is great for simple debugging. It exposes a text-based REPL debugger as well as a TCP interface. The REPL debugging leaves a bit to be desired compared to modern GUI debugging.

Enter node-inspector. Node Inspector is a tool that allows you to debug Node applications remotely from the browser. Node Inspector works by attaching to the debug port for a node application and allows you to set breakpoints, watches, modify code on the fly, and gives you a real-time console. Look at the documentation to install node-inspector.

Debugging using Node Inspector uses three separate ports:

  1. Application Port: The port your application will be running on
  2. Debug Port: The port node allows TCP debug attachment on, default is 5858
  3. Node-Inspector Port: The port that node-inspector runs on, default is 8080

In order to use node-inspector you will first fire up your application with the debug flag. When the debug flag is set, it will open a port (5858 by default) that will allow TCP connections to the debug environment for your application. You can specify the debug port as well.

node --debug server.js
node --debug=5859 server.js

You can then fire up node-inspector application, which listens on 8080 by default. This port can specified as well.

node-inspector
node-inspector --web-port=8000

Now that your application is running, a debug port is open, and node-inspector is running you can finally browse to node-inspector and your application. The URL for node-inspector takes as a query-string value the port that you want to debug.

For instance, if your application is running on 8080, debug on 5858, and node-inspector on 8000. You can access your application at http://localhost:8000/ and debug it with node-inspector by going to http://localhost:8000/debug?port=5858.