Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug Node.JS on VS Code EADDRINUSE error

I am trying to debug a Node.JS application on VS Code but, when the terminal opens, I get this message:

Error: listen EADDRINUSE :::5858

My application uses a framework called StrawJS (https://github.com/simonswain/straw) and it starts some different processes at the same time. I think that this is the cause of the error because there are many different processes trying to use the same debugger.

I found a similar question (VSCode will not stop on breakpoints when first node prcess forks a second) but configure the port on the attach.js file didn't work, the problem persists.

This is my actual launch.json file:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch",
        "type": "node",
        "request": "launch",
        "port": 5858,
        "program": "${workspaceRoot}/run.js",
        "stopOnEntry": false,
        "args": [],
        "cwd": "${workspaceRoot}",
        "preLaunchTask": null,
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "externalConsole": true,
        "sourceMaps": false,
        "outDir": null
    }
]}

Thank you!

like image 283
Geasi Puozzo Avatar asked Jul 12 '16 20:07

Geasi Puozzo


1 Answers

I had the same issue. If you started the node --debug from CMD, you have to only Attach to Process in your VS Code (if you try to launch it again from VS Code on the same port it will cause an error - this was my mistake).

Define the attach configuration object in launch.json with something like this:

{
    "type": "node",
    "request": "attach",
    "name": "Attach to Process",
    "port": 5858
}

choose Attach to Process in the dropdown in the upper left corner and press green play button - Start Debugging.

like image 116
ph0enix Avatar answered Sep 17 '22 05:09

ph0enix