Home  >  Article  >  Development Tools  >  How to debug nodejs with breakpoints in vscode

How to debug nodejs with breakpoints in vscode

青灯夜游
青灯夜游forward
2021-05-14 11:24:572627browse

How to debug nodejs with breakpoints in vscode

In normal front-end development, the front-end code can be easily debugged with breakpoints on the browser. So if you want to debug the node backend interface, how to implement breakpoint debugging?

Configuration

vscodeOpen the node project and click the debug button on the left

How to debug nodejs with breakpoints in vscode

Click Run and Debug

How to debug nodejs with breakpoints in vscode

Select the language as nodejs

How to debug nodejs with breakpoints in vscode

Click the settings button to add configuration

How to debug nodejs with breakpoints in vscode

[Recommended learning: "vscode tutorial"]

Change the lanuch.json configuration file

How to debug nodejs with breakpoints in vscode

Add your own project startup script file and configuration

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "启动程序",
            "env": {
                "NODE_ENV": "development"
            },
            "program": "${workspaceFolder}/bin/www"
        }
    ]
}
//program这个是我自己的node项目的启动文件

Click the breakpoint debugging button again to start breakpoint debugging

How to debug nodejs with breakpoints in vscode

Click directly on the startup program to start breakpoint debugging

How to debug nodejs with breakpoints in vscode

Put a breakpoint mark directly on the left side of the code where a breakpoint is required. The execution method will automatically trigger the breakpoint

How to debug nodejs with breakpoints in vscode

and then pass the above Debug button step by step breakpoint

How to debug nodejs with breakpoints in vscode

You can also see the breakpoint data by hovering the mouse

How to debug nodejs with breakpoints in vscode

Of course, you can also The result of the debug console console outputting breakpoint data is equivalent to the browser breakpoint console console

How to debug nodejs with breakpoints in vscode

If you want to end the breakpoint, just click the pause button above

How to debug nodejs with breakpoints in vscode

The above is the tutorial for the entire vscode breakpoint configuration and breakpoint debugging

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

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

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