Home >Web Front-end >JS Tutorial >Share several practical Node.js debugging methods, come and collect them! !

Share several practical Node.js debugging methods, come and collect them! !

青灯夜游
青灯夜游forward
2021-04-09 10:31:592182browse

This article will introduce to you several methods of Nodejs debugging. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Share several practical Node.js debugging methods, come and collect them! !

Related recommendations: "nodejs tutorial"

The first one


1. Open the vscode built-in terminal and select JavaScript Debug Terminal

Share several practical Node.js debugging methods, come and collect them! !

in the upper right corner. 2. In the code Break point (you need to enter debugger or mark Breakpoint at the breakpoint)

3. Run the execution command on the terminal

The second type


1. Mac select Debug: Toggle Auto Attach through the shortcut key and turn on Auto Attach (this method requires the node version It must be greater than 12)

2. Break the point in the code (you need to enter debugger or mark Breakpoint at the breakpoint)

3. Execute the code through the terminal command node --inspect index.js

The third type


Sometimes I look at some When opening an open source library, if you want to view the source code through breakpoints, you can specify the runtime execution environment by configuring launch.json

For example, package.json When debugging with scripts

Share several practical Node.js debugging methods, come and collect them! !

vscode, configure launch.json as follows

Share several practical Node.js debugging methods, come and collect them! !

Among them, runtimeExecutable specifies the execution environment of the runtime, specified here as npm, runtimeArgs specifies the execution parameters corresponding to the runtime execution environment, specified here Run run dev.

After configuring, press F5 to enable debugging. The actual execution is npm run dev, so that we can view the execution process of the code at the source code break point

For more debugging skills, you can check the vscode official website, Address

Fourth type


ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools

With the help ofndb, just as it is described on the official website,ndb Improved the debugging experience of nodejs by enabling a Chrome Devtools for debugging.

Before using it, you need to install it. You can pass npm install -g ndb. After installation, enter debugger where a breakpoint is required in the code. Then run ndb index.js, and you will find that a Chrome Devtools is opened and a breakpoint is already in place

Share several practical Node.js debugging methods, come and collect them! !

nodejs debugging is of course not limited to these types. Teacher Ruan has also written an article about nodejs debugger before. If you are interested, you can click to view Address

For more programming-related knowledge, please visit:Introduction to Programming ! !

The above is the detailed content of Share several practical Node.js debugging methods, come and collect them! !. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete