i

Debugging a Node application

We have discussed a lot of topics at length. But how can we debug an created Node.js application.

For this, we have a number of methods available

1. Using Command Line tools

2. GUI

3. And few others

Using Command-Line tools

1. Console.log is the simplest debugging mechanism. You can insert it at different points in the code block and find the state of the program.

2. Node’s built-in debugger Node uses a debugging interface provided by the V8 virtual machine. In order to stop the application execution, we can use Node’s use built-in debugger.

3. Node Inspector provides GUI for debugging Node program.

By default, node run on daemon port or PORT 8080 and can be launched using the command

node-inspector

following which you use

node debug-brk

Let's understand this with an example:

Create a javascript file named

debugging-demo.js

On Running       

   

Let's debug the application now

4. The pointer is currently at the anonymous function (highlighted)

 

Press n to move the pointer to run/debug the next statement

Which is

let index=0

(Highlighted in the undermentioned diagram)

Press n again to move the pointer to next executing statement
which is comparison operation inside the loop

Index<100 (highlighted)

Pressing n again

Pressing n again

Pressing n again (Highlighted)
applying comparison operator returning False

Pressing n
Applying increment operator

and so on.