NestJS 7.x 折腾记: (0) 起手式-> VS Code 1.5+ Debug NestJS

2,523 阅读1分钟

前言

随着7.x的到来,以及VS Code的不断完善.

NestJS的断点调试的开启比较容易.

效果图

image.png

配置流程

开启自动附加

Ctrl(CMD)+Shift+P --> Debug: Toggle Auto Attach

常规debug我们都是走inspect模式,所以看你习惯了

若是始终开启,有些常规的项目,会频繁报错进程异常 2020-11-02 17.46.37.gif

Debug(.vscode)

若是没有以下这两个文件(初始化),执行F5会报错,

然后可以根据引导进去调整.

也可以从"显示所有命令进入(cmd+shift+p)",如图 image.png image.png

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "启动程序",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/start",
            "preLaunchTask": "nest debug",
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ]
        }
    ]
}

tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "npm",
			"script": "start:debug",
			"group": "rebuild",
			"problemMatcher": [],
			"label": "nest debug",
			"detail": "nest start --debug --watch"
		}
	]
}

总结

有不对之处请留言, 会及时修正,谢谢阅读!