【问题标题】:Debugging 2 nodemon instances with VS Code on different ports在不同端口上使用 VS Code 调试 2 个 nodemon 实例
【发布时间】:2018-12-05 11:01:48
【问题描述】:

我目前正在开发一个完全使用 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

是否可以在另一个端口上使用调试器?

【问题讨论】:

    标签: visual-studio-code nodemon vscode-debugger


    【解决方案1】:

    使用--inspect=<port> 指定调试器应该运行哪个端口。

    例子:

    对于客户端应用程序,在调试器的默认端口(即 9229)上运行 -

    "dev": "nodemon --inspect ./index.js"
    

    对于服务器应用程序,在端口 9228 上运行调试器 -

    "dev": "nodemon --inspect=9228 ./index.js"
    

    【讨论】:

      猜你喜欢
      • 2020-06-02
      • 1970-01-01
      • 2018-07-21
      • 2020-07-05
      • 2017-08-09
      • 2018-05-13
      • 2019-10-28
      • 2016-10-18
      • 2020-01-27
      相关资源
      最近更新 更多