How do I debug Node.js applications?

后端 未结 30 2706
暗喜
暗喜 2020-11-22 05:56

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         


        
30条回答
  •  半阙折子戏
    2020-11-22 06:40

    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:

    
    

    Now load the file in your browser and press F12 and viola: debug in browser.

提交回复
热议问题