在不同端口上使用 VS Code 调试 2 个 nodemon 实例
Debugging 2 nodemon instances with VS Code on different ports
我目前正在开发一个完全使用 Node.js 的应用程序,因此同时有 2 个 nodemon 实例 运行ning,client
和 server
:
.
|-- README.md
|-- client
| |-- index.js
| |-- node_modules
| |-- package-lock.json
| `-- package.json
`-- server
|-- index.js
|-- node_modules
|-- package-lock.json
`-- package.json
4 directories, 7 files
这是VS Code中打开的目录。在 package.json
的 scripts
部分中,我有以下内容:
"dev": "nodemon --inspect ./index.js"
我研究了如何调试 nodemon 实例,我在 VS Code 的存储库中找到了这个配置:
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
}
]
但现在的问题是,当我同时运行这两个脚本时,我的终端出现以下错误:Starting inspector on 127.0.0.1:9229 failed: address already in use
是否可以在另一个端口上使用调试器?
使用--inspect=<port>
指定调试器应该运行的端口。
示例:
对于客户端应用程序,在调试器的默认端口(即 9229)上 运行 -
"dev": "nodemon --inspect ./index.js"
对于服务器应用程序,到 运行 端口 9228 上的调试器 -
"dev": "nodemon --inspect=9228 ./index.js"
我目前正在开发一个完全使用 Node.js 的应用程序,因此同时有 2 个 nodemon 实例 运行ning,client
和 server
:
.
|-- README.md
|-- client
| |-- index.js
| |-- node_modules
| |-- package-lock.json
| `-- package.json
`-- server
|-- index.js
|-- node_modules
|-- package-lock.json
`-- package.json
4 directories, 7 files
这是VS Code中打开的目录。在 package.json
的 scripts
部分中,我有以下内容:
"dev": "nodemon --inspect ./index.js"
我研究了如何调试 nodemon 实例,我在 VS Code 的存储库中找到了这个配置:
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
}
]
但现在的问题是,当我同时运行这两个脚本时,我的终端出现以下错误:Starting inspector on 127.0.0.1:9229 failed: address already in use
是否可以在另一个端口上使用调试器?
使用--inspect=<port>
指定调试器应该运行的端口。
示例:
对于客户端应用程序,在调试器的默认端口(即 9229)上 运行 -
"dev": "nodemon --inspect ./index.js"
对于服务器应用程序,到 运行 端口 9228 上的调试器 -
"dev": "nodemon --inspect=9228 ./index.js"