Debugging 2 nodemon instances with VS Code on different ports

2.5k views Asked by At

I am currently developing an app entirely with Node.js, and have therefore 2 nodemon instances running at the same time, the client and the 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

So this is the opened directory in VS Code. In the scripts section of both package.json I have the following : "dev": "nodemon --inspect ./index.js"

I made some research on how to debug a nodemon instance, and I found this configuration on VS Code's repository :

"configurations": [
    {
        "type": "node",
        "request": "attach",
        "name": "Node: Nodemon",
        "processId": "${command:PickProcess}",
        "restart": true,
        "protocol": "inspector",
    }
]

But now the problem is, when I run the two scripts at the same time, I have the following error in my terminal : Starting inspector on 127.0.0.1:9229 failed: address already in use

Is it possible to use the debugger on another port ?

1

There are 1 answers

0
Aswin Sanakan On BEST ANSWER

Use --inspect=<port> to specify which port the debugger should run.

Example:

For Client app, to run on default port for debugger (i.e, 9229) -

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

For Server app, to run debugger on port 9228 -

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