Understanding the use of debugger in Node.js

Node.jsServer Side ProgrammingProgramming

In earlier example, we used debugger in vs code to check any logical error. In this article we will look into how to use debug console and restarting debugger automatically on changes.

In debug console, we can also type an expression and evaluate its result beforehand. This is very useful in finding logical errors.

In left menu’s we can also see variables and expressions in watch like −

In variables section, developer can change the values of variable by double clicking on its values and edit. This will directly change in app runtime and will take effect of values.

Example of such a one change is: See the username field is changed to tutorials point instead of test.

How to enable auto restart in debug mode on any code changes

Go to Run -> Add Configuration

We will see launch.json file opened on add configuration click −

launch.json −


In configurations, add restart option −

“restart” : true

Also runtimeExecutable −

“runtimeExecutable”:”nodemon”

Optionally we can add console messages −

“console”: “integratedterminal”

Now, we can save changes and start debugger again. This time if any code changes added, nodemon will auto restart debugger from App.js file

Here, we will require nodemon to be installed globally else it will fail. To install it globally

Use command: npm install nodemon –g

On mac os , sudo may be required in front of npm install

raja
Published on 13-May-2020 16:06:15
Advertisements