How do I debug Node.js applications?

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

    I created a neat little tool called pry.js that can help you out.

    Put a simple statement somewhere in your code, run your script normally and node will halt the current thread giving you access to all your variables and functions. View/edit/delete them at will!

    var pry = require('pryjs')
    
    class FizzBuzz
    
      run: ->
        for i in [1..100]
          output = ''
          eval(pry.it) // magic
          output += "Fizz" if i % 3 is 0
          output += "Buzz" if i % 5 is 0
          console.log output || i
    
      bar: ->
        10
    
    fizz = new FizzBuzz()
    fizz.run()
    

提交回复
热议问题