Debugging the debugger

Sergey Krilov edited this page Dec 18, 2013 · 4 revisions


Node-inspector consists of two parts, front-end (browser) and back-end (node). The front-end consists of the web inspector code from WebKit and some adapter code that communicated with the back-end. The back-end code is a node process that proxies messages from the front-end and the node debugger back and forth. Either part can be debugged independently or simultaneously. Hold on, cuz things might get a little weird. And remember, the bug you’re debugging is also in the debugger you’re debugging with (just hopefully not at the same point in time). Good Luck :)

Debugging the front-end

This is the easiest to set up. Just start your browser’s debugger while on the node-inspector page. Node specific code is in the front-end/node folder, thats a good place to start.

Debugging the back-end

It’s easiest to explain this procedure with an example. This example assumes you are debugging an HTTP application located at hello.js running on port 8000. You will be launching one instance of node-inspector to debug the app, and another instance of node-inspector to debug the first instance.

At the end you will have 3 pages running:

  • (#1) Test app: This is a node application running hello.js on port 8000, started in debug mode. If you have a specific application you want to debug, you should substitute the path and the port appropriately while following the steps below. Otherwise, grab the Hello HTTP example from here and save it as hello.js.
  • (#2) Debug target: This is instance 1 of node-inspector (which is debugging hello.js). This instance needs to be running from source (i.e., launched from bin/inspector.js in the cloned repository), and it needs to be launched in debug mode; however, you need to assign it a debug port that is different from the default 5858, which is already taken by the test app’s debugger. You can do this by setting the --debug parameter to a specific value; e.g., node --debug=7878 bin/inspector.js.

Note that the globally-installed node-inspector (installed using npm install -g node-inspector) cannot be used as the debug target; however, you may use it as your working debugger for the next part.

  • (#3) Working debugger: This is instance 2 of node-inspector (which is debugging instance 1). For this, you may use either the globally-installed node-inspector, or just start a second instance from source. The important part is you need to give this instance a different web port to listen on (e.g., using --web-port 9090), and you also need to point Node Inspector to the correct V8 debugger port for instance 1 (e.g., using --debug-port 7878).


Here are the steps to get all of these up and running:

  1. Start your test app:
    1. Run node --debug hello.js in the terminal.
    2. Open http://localhost:8000 in the browser.
  2. Start instance 1 of node-inspector:
    1. Run node --debug=7878 bin/inspector.js in the terminal.
    2. Open http://localhost:8080/debug?port=5858 in the browser.
  3. Start instance 2 of node-inspector:
    1. Run node bin/inspector.js --web-port 9090 --debug-port 7878 in the terminal.
    2. Open http://localhost:9090/debug?port=7878 in the browser.

Your second node-inspector should now be connected to the back-end of the first node-inspector. Use (#3) to set breakpoints on (#2). Interact with (#2) to hit your breakpoints. Setting breakpoints on (#2) will debug (#1). Got it? Easy as pie!

All the way

To debug both front-end and back-end together, just combine the above methods for a total of 4 pages.


With all that mess, you can debug node-inspector debugging another app. For the full “meta” experience try this while travelling at a sufficiently ludicrous speed and watch yourself debugging the debugger thats debugging your app :)