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.inspect(someVariable));
There must be a better way to debug. I know that Google Chrome has a command-line debugger. Is this debugger available for Node.js as well?
Node.js version 0.3.4+ has built-in debugging support.
node debug script.js
Manual: http://nodejs.org/api/debugger.html
Use this commands
Node has its own built in GUI debugger as of version 6.3 (using Chrome's DevTools)
Simply pass the inspector flag and you'll be provided with a URL to the inspector:
You can also break on the first line by passing
--inspect-brk
instead.To open a Chrome window automatically, use the inspect-process module.
Visual Studio Code has really nice Node.js debugging support. It is free, open source and cross-platform and runs on Linux, OS X and Windows.
You can even debug grunt and gulp tasks, should you need to...
The NetBeans IDE has had Node.js support since version 8.1:
Additional references:
Visual Studio Code will work for us in debugging.