Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of debugging node.js in vscode

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the method of debugging node.js in vscode, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

In vscode, click the spider button

You can see the sidebar where debug appears, and then add the configuration

Select environment

You can see launch.json 's file.

When starting, select the appropriate configuration, and then click the green triangle that points to the right

Launch mode and attach mode

When request is launch, it is launch mode, this is where the program is started from vscode, if you are debugging, it will always be in debug mode. Attach mode, on the other hand, is to connect to a service that has already been started. For example, if you have started the project outside, you suddenly need to debug. You don't need to shut down the started project and restart it in vscode. As long as you start it in attach mode, vscode can connect to the already started service. When debugging is over, just disconnect, which is obviously a little more convenient than launch.

Start with npm in debug

In many cases, we write long startup commands and configurations in the scripts of package.json, such as:

We want vscode to start and debug using npm, which requires the following configuration:

Start with nodemon in debug

Just using npm to start, although nodemon is used in the dev command, the program can be restarted normally, but after the restart, the debugging is disconnected. So you need to get vscode to start the project using nodemon.

Notice the runtimeArgs here, if these configurations are written in package.json, that's what it looks like.

Nodemon-inspect-exec babel-node-presets env. / bin/www

This is very convenient, the project can be restarted normally, each restart will also turn on the debugging function.

However, what if we don't want to turn on debugging all the time? This requires the use of the attach mode mentioned above.

Start the project normally using the following command

Nodemon-inspect-exec babel-node-presets env. / bin/www

When we want to debug, run the following configuration in the debug of vscode

Thank you for reading this article carefully. I hope it will be helpful for everyone to share the methods and contents of node.js debugging in vscode. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report