a blog for those who code

Saturday 23 August 2014

Debugger in Nodejs

Node.js comes with a built-in debugger which we can use with our Node applications. In this post we will explain you the process of debugging in Node.js .

The process start with adding debugger statement into your code, any place where you want a break point.

Now, you have to run your application is debug mode like node debug app.js

In this debug mode the application at first stops at the beginning of the file. Now, to go to the first breakpoint, you have to type cont or c. This causes the debugger to stop at the first breakpoint and waits until it gets input from the user.

You have many options at this point, they are

1. step through the code using next (n) command,
2. step into a function using step (s) command,
3. out of a function using out (o) command.

You can also set a new breakpoint, either on the current line setBreakpoint (sb) or the first line in a named function or script file. You can also clear a breakpoint, with clearBreakpoint (cb). The backtrace command is helpful for printing a backtrace of the current execution frame.

Any time if you want to see what commands are available to you, you can type help.

Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment