无论是开发还是阅读源码,都少不了debug。怎样在VSCode中调试nodejs代码呢?
1. 配置launch.json
{
// 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": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/tmp.js",
"runtimeExecutable": "/Users/yyy/.nvm/versions/node/v12.14.1/bin/node"
}
]
}
- 需要将program 配置成需要debug的入口文件。比如,我这里debug的文件是根目录下的tmp.js。
所以添加如下配置:
"program": "${workspaceFolder}/tmp.js",
其中,${workspaceFolder}代表项目的根目录。
2)runtimeExecutable:填node的安装目录,mac中可以用where 命令查找安装路径。
然后就可以愉快地debug了~