nestjs笔记一:创建工程并配置vscode调试环境
环境准备
1.准备好node环境
去www.nodejs.org下载一个node版本安装。这里就不说了
2.准备好nestjs环境
在命令行输入:
npm i -g @nestjs/cli
完成后,nest的cli工具就可以用了
创建工程
nest new demo
配置vscode开发环境
启动vscode
cd demo
code .
配置任务
1.vscode 菜单->终端->运行任务
2.在任务列表下拉框选择:配置任务
3.在要选择的配置任务列表,我们这里选择npm: build 注:这些都是package.json中script中的东西
然后就会创建一个任务文件,在.vscode目录下录 tasks.json 内容如下:
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"group": "build",
"problemMatcher": [],
"label": "npm: build",
"detail": "nest build"
}
]
}
这样完成了任务的配置
配置启动
1.在左侧工具栏,选择调试
2.选择创建launch.json
3.选择运行环境列表,选择node
4.然后如下配置
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "./dist/main.js"
}
]
}
5.配置任务和输出终端后,如下
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"console":"integratedTerminal",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\dist\\main.js",
"preLaunchTask": "npm: build",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}
完成后,保存,就可以按F5调试了
|