node的基本调试

vscode调试

断点

无须多言

模式

两种模式

  • 一种是通过node的launch,也就是直接启动项目的入口。这种方式最为直接,但是实际上并不是很方便,因为每一次调试都需要重新启动项目。
  • 另一种是通过attach的方式,使用node-inspector进行调试。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/build/app.js",
"sourceMaps": true,
"outFiles": [ // 该选项指定了map文件的寻找路径
"build"
]
},
{
"type": "node",
"request": "attach",
"name": "附加",
"port": 5858,
"timeout": 10000,
"restart": true,
"address": "localhost",
"sourceMaps": true,
"outFiles": [
"build"
]
}
]
}

参考资料

NodeJS的代码调试和性能调优