Home Development Tools VSCode How to debug node in vscode

How to debug node in vscode

Dec 06, 2019 pm 05:11 PM
node vscode debug

How to debug node in vscode

#1. Create a configuration file

1. Select your project

How to debug node in vscode

2. Select the language of your project

How to debug node in vscode

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"
        }
    ]
}
Copy after login

type - The debugger type used for this launch configuration. Each installed debugging extension introduces a type, for example, the node built-in node debugger, php and the goPHP and Go extensions.

request - The request type for this launch configuration. Currently supported are launch and attach. (See Chapter 3 below for a detailed explanation of request)

name - Friendly name, displayed in the "Debug Launch Configuration" drop-down list.

program - The executable or file to run when the debugger is started.

args - Arguments passed to the program for debugging.

env - environment variable (the value null can be used to "undefine" the variable).

cwd - The current working directory, used to find dependencies and other files.

Note 1: ${workspaceFolder} represents the root path of the workspace folder, ${file} represents the file opened in the active editor.

Note 2: "program": "${workspaceFolder}/test.js", I'm not sure how vscode recognizes /test.js in the current directory I want to debug. [To be solved]

Note 3: You can also write the configuration file into User Settings to become a global configuration.

How to debug node in vscode

4. Quickly return to your configuration file

How to debug node in vscode

2. Breakpoint

1. Breakpoint (traditional breakpoint)

(1) The graphics are replaced by circles;

(2) cannot be typed on a blank line.

How to debug node in vscode

2. Logpoint

(1) You can print out information in the debug console (wrap expressions with {});

(2) The graphics are replaced by diamonds;

(3) If it is not placed on the statement, but on a blank line, it will disappear during debugging and execution, but the effect will not be affected. So it is still recommended to type in the sentence!

How to debug node in vscode

3. Conditional Breakpoint

is divided into two conditions: expression/number of hits

(1) You can break to the statement closest to the breakpoint when the conditions are met;

(2) The graphic is replaced by a square;

(3) If you do not hit the statement, but A blank line will disappear during debugging, but will not affect the effect.

3. Debugging

#The launch.json configuration file mentioned in Chapter 1 has a request field, and the value range is: launch and attach

launch: vscode e runs a debugging process independently

attach: You start debugging by yourself through node --inspect-brk xxx.js, and then vscode attaches it

Let’s talk about the difference between specific debugging methods in these two categories:

1. Launch method

(1) Click Launch Program

How to debug node in vscode

(2) Select which configuration file to launch

How to debug node in vscode

Note: The value of the name attribute in the launch.json configuration file will be displayed here drop-down list.

(3) Start debugging

2. Attach method

(1) Turn on Auto Attach: On

How to debug node in vscode

(2)以调试的方式启动 node

node --inspect-brk test.js
Copy after login

(3)开始调试

四、调试相关功能

1、DEBUG CONSOLE

可以在此操作变量

How to debug node in vscode

五、多目标调试

需求:同时调试 server.js 和 client.js

1、建立配置文件

{
    "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"]
        }
    ]
}
Copy after login

2、开始调试

注1:调试的时候,可以同时运行程序。

注2:当修改代码,同时运行的程序会立即生效,而调试的代码还是老的。

PHP中文网,有大量免费的vscode入门教程,欢迎大家学习!

The above is the detailed content of How to debug node in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add files to vscode workspace How to add files to vscode workspace How to add files to vscode workspace How to add files to vscode workspace May 09, 2024 am 09:43 AM

1. First, open the vscode software, click the explorer icon, and find the workspace window 2. Then, click the file menu in the upper left corner and find the add folder to workspace option 3. Finally, find the folder location in the local disk , click the add button

How to enable background updates in vscode How to enable background updates in vscode How to enable background updates in vscode How to enable background updates in vscode May 09, 2024 am 09:52 AM

1. First, after opening the interface, click the file menu in the upper left corner. 2. Then, click the settings button in the preferences column. 3. Then, in the settings page that jumps, find the update section. 4. Finally, click the mouse to check and enable it. Download and install the new VSCode version button in the background on Windows and restart the program.

How to disable wsl configuration file in vscode How to disable wsl configuration file in vscode How to disable wsl configuration file in vscode How to disable wsl configuration file in vscode May 09, 2024 am 10:30 AM

1. First, open the settings option in the settings menu. 2. Then, find the terminal column in the commonly used page. 3. Finally, uncheck the usewslprofiles button on the right side of the column.

How to set animation smooth insertion in VScode VScode tutorial to set animation smooth insertion How to set animation smooth insertion in VScode VScode tutorial to set animation smooth insertion May 09, 2024 am 09:49 AM

1. First, after opening the interface, click the workspace interface 2. Then, in the open editing panel, click the File menu 3. Then, click the Settings button under the Preferences column 4. Finally, click the mouse to check the CursorSmoothCaretAnimation button and save Just set it

How to open workspace trust permissions in Vscode Vscode method to open workspace trust permissions How to open workspace trust permissions in Vscode Vscode method to open workspace trust permissions May 09, 2024 am 10:34 AM

1. First, after opening the editing window, click the configuration icon in the lower left corner 2. Then, click the Manage Workspace Trust button in the submenu that opens 3. Then, find the page in the editing window 4. Finally, according to your office Just check the relevant instructions if required

How to use LeakSanitizer to debug C++ memory leaks? How to use LeakSanitizer to debug C++ memory leaks? Jun 02, 2024 pm 09:46 PM

How to use LeakSanitizer to debug C++ memory leaks? Install LeakSanitizer. Enable LeakSanitizer via compile flag. Run the application and analyze the LeakSanitizer report. Identify memory allocation types and allocation locations. Fix memory leaks and ensure all dynamically allocated memory is released.

How to open animation in Vscode Introduction to the method of opening animation in Vscode How to open animation in Vscode Introduction to the method of opening animation in Vscode May 09, 2024 am 10:28 AM

1. First, click to open the settings option in the More menu. 2. Then, find the terminal column under the Features section. 3. Finally, on the right side of the column, click the enableanimation button with the mouse and save the settings.

How to set the file icon theme in vscode_How to set the file icon theme in vscode How to set the file icon theme in vscode_How to set the file icon theme in vscode May 09, 2024 am 10:00 AM

1. After opening the interface, click the extension button in the lower left corner 2. Search for the vscode-icons plug-in in the extension store and install it 3. Then click the preferences button in the file menu in the upper left corner to find the file icon theme option 4. Find the just installed Just set the plug-in

See all articles