How do I debug a Node.js server application?
Right now I\'m mostly using alert debugging with print statements like this:
sys.puts(sys.inspe
ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools
https://github.com/GoogleChromeLabs/ndb
I wrote a different approach to debug Node.js code which is stable and is extremely simple. It is available at https://github.com/s-a/iron-node.
An opensource cross-platform visual debugger.
Installation:
npm install iron-node -g;
Debug:
iron-node yourscript.js;
node-inspector could save the day! Use it from any browser supporting WebSocket. Breakpoints, profiler, livecoding, etc... It is really awesome.
Install it with:
npm install -g node-inspector
Then run:
node-debug app.js
I personally use JetBrains WebStorm as it's the only JavaScript IDE that I've found which is great for both frontend and backend JavaScript.
It works on multiple OS's and has Node.js debugging built-in (as well as a ton of other stuff](http://www.jetbrains.com/webstorm/features/index.html).
My only 'issues'/wishlist items are were:
IntelliJ works wonderfully for Node.js.
In addition, IntelliJ supports 'Code Assistance' well.
A quick-and-dirty way to debug small Node.js scripts with your favorite browser debugger would be to use browserify. Note that this approach doesn't work with any applications which require native I/O libraries, but it is good enough for most small scripts.
$ npm install -g browserify
Now move all your var x = requires('x')
calls into a requires.js
file and run:
$ browserify requires.js -s window -o bundle.js
(The downside here is that you either have to move or comment the requires
in all your files.)
Include the bundle.js
in an HTML file like so:
<script type="text/javascript" src="bundle.js"></script>
Now load the file in your browser and press F12 and viola: debug in browser.