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 :)
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.
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:
bin/inspector.jsin 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
--debugparameter to a specific value; e.g.,
node --debug=7878 bin/inspector.js.
Note that the globally-installed
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.
--web-port 9090), and you also need to point Node Inspector to the correct V8 debugger port for instance 1 (e.g., using
Here are the steps to get all of these up and running:
node --debug hello.jsin the terminal.
http://localhost:8000in the browser.
node --debug=7878 bin/inspector.jsin the terminal.
http://localhost:8080/debug?port=5858in the browser.
node bin/inspector.js --web-port 9090 --debug-port 7878in the terminal.
http://localhost:9090/debug?port=7878in 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!
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 :)