gpt4 book ai didi

visual-studio-code - 在不同端口上使用 VS Code 调试 2 个 nodemon 实例

转载 作者:行者123 更新时间:2023-12-02 00:32:59 24 4
gpt4 key购买 nike

我目前正在开发一个完全使用 Node.js 的应用程序,因此有 2 个 nodemon 实例同时运行,clientserver:

.
|-- 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.jsonscripts 部分,我有以下内容:"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"

关于visual-studio-code - 在不同端口上使用 VS Code 调试 2 个 nodemon 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51047706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com