Debugging Node.js with Node-Inspector
Today I had another mind-blowing experience.
As I was writing a software project in Node, which has reached it's critical level for me, where I just don't want to go on, with sys.puts and sys.inspect to find out, what my code is doing, I was in search of a Debugger for node.
Yesterday I tried out Cloud9's Javscript IDE, but while being really a great project, is still in the very beginnings and I wasn't able to set breakpoints in Chrome nor in Firefox. Perhaps I was doing something wrong, but it just didn't work out of the box for me and I couldn't find any documentaion yet. Anyways, Cloud9 is going to be really a great IDE some day!
So I was tinkering around and remembered, that I came accross a link to a project that involves Webkit's Web Inspector as a debugger for Node.js. The Project is called Node- Inspector.
A npm install node-inspector gave me a good start and I got all that was necessary on my system.
Node-Inspector itsself is written in Javascript as it should be and runs with node. ;) The way node-inspector works is that it spawns a Webserver on port 8080 by default, where you can see Web Inspectors debugger Interface. Then it connects to Node's Debug port, which in my case is 5858.
There is some confusion in the Readme and the screencast of how to startup node-inspector.
However a fast node --help, made things clear.
So here is my Installation Instruction:
Start node-inspector, by typing: node-inspector& (this will start the Webserver)
Startup your favourite Webkit browser (e.g. Safari, Chrome, etc) and go to 127.0.0.1:8080
start node with the --debug-brk option. This will start a TCP debug port at 5858 and set a startup breakpoint on the first line of your Javascript file.
So if youR Javascript file is called "hello.js".
node --debug-brk hello.js will startup things.
Now go back to your browser and hit the "Connect to Node" button.
all your node are belong to us now!
Web Inspector is about the greatest debugger around and seeing it full screen debugging node is just mind-blowing cool!