Tuesday, December 17, 2013

How to debug in node.js

1. Sample program:

~> vim hello-world.js

setTimeout(function(){
                console.log("world");
        }, 2000)

        console.log("hello");

        function foo() {
                debugger;
        return 1 + 2;
        }


2. Run the program as:
~> node debug hello-world.js

You get:

< debugger listening on port 5858
connecting... ok
break in hello-world.js:1
  1     setTimeout(function(){
  2         console.log("world");
  3     }, 2000)
debug> backtrace

#0 hello-world.js:1:64
debug>

No comments:

Post a Comment