How do I debug Node.js applications?

后端 未结 30 2071
暗喜
暗喜 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:31

    ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools

    https://github.com/GoogleChromeLabs/ndb

    0 讨论(0)
  • 2020-11-22 06:32

    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.

    Enter image description here

    An opensource cross-platform visual debugger.

    Installation:

    npm install iron-node -g;

    Debug:

    iron-node yourscript.js;

    0 讨论(0)
  • 2020-11-22 06:33

    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
    
    0 讨论(0)
  • 2020-11-22 06:33

    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:

    1. It seems to be more resource hungry on Mac than Windows It no longer seems an issue in version 6.
    2. It would be nice if it had Snippet support (like those of Sublime Text 2 - i.e. type 'fun' and tap 'tab' to put in a function. See @WickyNilliams comment below - With Live Templates you also have snippet support.
    0 讨论(0)
  • 2020-11-22 06:35

    IntelliJ works wonderfully for Node.js.

    In addition, IntelliJ supports 'Code Assistance' well.

    0 讨论(0)
  • 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:

    <script type="text/javascript" src="bundle.js"></script>
    

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

    0 讨论(0)
提交回复
热议问题