In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how vscode debugs node. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
First, establish a configuration file
1. Choose your project
2. Choose the language of your project
3. Generate .vscode / launch.json under the current project path
{/ / Use IntelliSense to learn about possible attributes. / / Hover to view descriptions of existing attributes. / / For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [{"type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder} / test.js"}]}
Type-the type of debugger used for this startup configuration. Each installed debug extension introduces a type, such as the node built-in node debugger, php, and goPHP and Go extensions.
Request-the request type for this startup configuration. Currently, launch and attach are supported. (for a detailed explanation of request, see Chapter 3 below)
Name-friendly name, displayed in the Debug Startup configuration drop-down list.
Program-the executable or file to run when the debugger is started.
Args-parameters passed to the program for debugging.
Env- environment variable (this value null can be used for the Undefine variable).
Cwd-the current working directory for finding dependencies and other files.
Note 1 ${workspaceFolder} represents the root path of the workspace folder, and ${file} represents the open file in the active editor.
Note 2: "program": "${workspaceFolder} / test.js", I'm not sure how vscode recognizes the / test.js I want to debug in the current directory. [to be solved]
Note 3: you can also write the configuration file into User Settings as a global configuration.
4. Get back to your configuration file quickly
Second, break point
1. Breakpoint (traditional breakpoint)
(1) the figure is replaced by a circle.
(2) do not type on the blank line.
2 、 Logpoint
(1) you can print out information in debug console (using {} package expression)
(2) the figure is replaced by a diamond.
(3) if the blank line is not typed on the statement, the debugging will disappear, but the effect will not be affected. So it is recommended to type on the sentence!
3 、 Conditional Breakpoint
There are two conditions: expression / hit number
(1) when the condition is met, you can interrupt to the statement closest to the breakpoint.
(2) the figure is replaced by square.
(3) if the blank line is not typed on the statement, the debugging will disappear, but the effect will not be affected.
III. Debugging
The launch.json configuration file mentioned in Chapter 1 contains request fields with values ranging from launch and attach
Launch:vscod e runs a debugging process independently.
Attach: you start debugging yourself through node-- inspect-brk xxx.js, and then vscode goes to attach it.
The following is divided into these two categories to talk about the differences in specific debugging methods:
1. Launch mode
(1) Click Launch Program
(2) Select which configuration file to launch
Note: the value of the name property in the launch.json configuration file is displayed in this drop-down list.
(3) start debugging
2. Attach mode
(1) Open Auto Attach:On
(2) start node by debugging
Node-inspect-brk test.js
(3) start debugging
IV. Debugging related functions
1 、 DEBUG CONSOLE
You can manipulate variables here
5. Multi-target debugging
Requirements: debug both server.js and client.js
1. Establish a configuration file
{"version": "0.2.0", "configurations": [{"type": "node", "request": "launch", "name": "Server", "program": "${workspaceFolder} / server.js", "cwd": "${workspaceFolder}"} {"type": "node", "request": "launch", "name": "Client", "program": "${workspaceFolder} / client.js", "cwd": "${workspaceFolder}"}], "compounds": [{"name": "Server/Client" "configurations": ["Server", "Client"]}]}
2. Start debugging
Note 1: when debugging, you can run the program at the same time.
Note 2: when the code is modified, the program running at the same time will take effect immediately, and the debugged code is still old.
Thank you for reading! This is the end of this article on "vscode debugging node". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.