Using node-inspector to debug node.js applications including on Windows (and using ...
Update: You can now use npm to install node-inspector and do not need ryppi.py. npm is included as part of the node installation at http://www.nodejs.org. I’ve updated the post to use npm.
Yesterday I came across node-inspector while reading the “Hands on node.js” ebook. Node-inspector is a nifty node module by Danny Coates that introduces a visual debugger for stepping through your node apps. Yes modules are much more than just libraries folks!
Here are some of the cool features it offers.
- Step through
- Evaluations including accessing server-side objects like console
- Edit & Continue – You can change code on the fly and continue executing.
I installed it on my Mac book pro without a hitch through using npm, the node package manager. You can follow the directions here. Once it is installed you can launch node-inspector using code similar to the following.
Next you open your browser to “http://localhost:8080” and voila you are in the debugger!
Here’s a screenshot of how it looks. In this case I am messing with evaluating a few expressions on the fly.
I sent an email to a bunch of folks talking about how cool node-inspector was. I then got back a reasonable question, “Does it work on Windows?”.
Short answer, “no”, that is not out of the box. However, with a slight change you can make it work. There’s a bunch of steps however to get to the point where you can even make that fix . Read on…..
Before you get started, you will need to use either Google Chrome or Safari as your browser as node-inspector depends on webkit.
The first problem you hit into though is how to get all the packages in the first place. Fortunately npm has now been ported to Windows. If you install node from http://www.nodejs.org , npm is included. Once I had npm, “npm install node-inspector” is all I needed to get going.
Once I got the packages installed I then found node-inspector didn’t appear to be working. When accessing the debugger via the browser, my browser returned an HTTP Status Code of 403. Searching around the internet I came across this comment which shows how you how to patch the “paperboy” module to make it work. Once I did that I was happy to see when I launched node-inspector plus node it worked.
Below are the steps to take you from 0 (node not on the machine) to node-inspector working. Install time, about 15 mins.
- Install node here.
- Create a root folder your source project will live i.e. “c:\code”. Your modules will live here as well.
- Open a new command prompt and go to the code folder you just created.
- Use this command to get node-inspector, “npm install node-inspector”. You will notice a bunch of modules are downloaded.
- After the download is complete you should see a “node_modules” folder in your code folder.
- Now comes the patch. In your modules folder you will see a module called “paperboy”. Go into that folder and edit the lib\paperboy.js file.
- Replace the filepath function with the code you see below.
Now we’re all set to use the debugger.
- Launch node-inspector “node_modules/.bin/inspector &”.
- Open a new command window.
- Change to the folder where your node project that you want to debug lives.
- Launch node with the following command “node –debug-brk app.js” (substitute app.js for whatever js you want to use)
- Open up your browser (Chrome or Safari) to http://localhost:8080.
If you followed all the steps I described you should see the debugger and be ready to go!
The steps above to get node-inspector working are really a point-in-time issue. First, npm for Windows is in progress. Second, a patch has been submitted to paperboy to fix this problem.
Still and all though it took me a few hours to get there, it will take you 15 minutes now by following the directions (assuming you already have git installed ).