Running VS Code debugger seems to host my web app

858 views Asked by At

When I just run the vs code debugger without using npm start, it seems to host my app because I can browse to it in Chrome without even running npm start. My app is on port 3000 and my debugger on port 5858. It wasn't having this issue earlier today. I get this error when running my angular universal app and then also running my debugger to debug the node.js backend because two processes are trying to use the same port. It means I can't trigger my backend functions by using the GUI so it's making it hard to test the backend. Why does debugging my app seem to host it?

Here is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [{
        "name": "Launch",
        "type": "node2",
        "request": "launch",
        "program": "${workspaceRoot}/src/server.ts",
        "stopOnEntry": false,
        "skipFiles": [
            "node_modules/**/*.js"
        ],
        "args": [],
        "cwd": "${workspaceRoot}",
        "preLaunchTask": null,
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "externalConsole": false,
        "sourceMaps": true,
        "outFiles": ["${workspaceRoot}/dist/**/*.js"],
        "address": "localhost",
        "port": 5858
    }, {
        "name": "Attach",
        "type": "node2",
        "request": "attach",
        "port": 5858,
        "address": "localhost",
        "restart": false,
        "sourceMaps": false,
        "outDir": null,
        "localRoot": "${workspaceRoot}",
        "remoteRoot": null
    }, {
        "name": "Attach to Process",
        "type": "node2",
        "request": "attach",
        "processId": "${command.PickProcess}",
        "port": 5858,
        "sourceMaps": false,
        "outDir": null
    }]
}

Here is the debug console when I am not hosting my app with npm start:

node --inspect=5858 --debug-brk --nolazy dist/server/index.js 
Debugger listening on port 5858.
Warning: This is an experimental feature and could change at any time.
Debugger attached.
slimy sam
slimy sam
Listening on: http://localhost:3000

Here is the debug console when I am already hosting my app with npm start:

node --inspect=5858 --debug-brk --nolazy dist/server/index.js 
Debugger listening on port 5858.
Warning: This is an experimental feature and could change at any time.
Debugger attached.
slimy sam
events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at Server._listen2 (net.js:1257:14)
    at listen (net.js:1293:10)
    at Server.listen (net.js:1389:5)
    at EventEmitter.listen (/private/var/root/vepo/node_modules/express/lib/application.js:617:24)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57532:18)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57537:30)
    at __webpack_require__ (/private/var/root/vepo/dist/server/index.js:27:30)
    at /private/var/root/vepo/dist/server/index.js:93:18
Waiting for the debugger to disconnect...

EDIT: It also stops the debugger on entry when I have set it to false in the launch.json so maybe my vs code is just broken. I may need to reinstall it although I'm trying to avoid it since I have quite a lot of extensions.

When I change the port my app runs on to 4000 I get the same error when I debug but for 4000:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: listen EADDRINUSE :::4000
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at Server._listen2 (net.js:1257:14)
    at listen (net.js:1293:10)
    at Server.listen (net.js:1389:5)
    at EventEmitter.listen (/private/var/root/vepo/node_modules/express/lib/application.js:617:24)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57532:18)
    at Object.<anonymous> (/private/var/root/vepo/dist/server/index.js:57537:30)
    at __webpack_require__ (/private/var/root/vepo/dist/server/index.js:27:30)
    at /private/var/root/vepo/dist/server/index.js:93:18
Waiting for the debugger to disconnect...
1

There are 1 answers

5
Shekhar Tyagi On

It seems that you have two apps running on the same port no 1.e 3000.

Use this command

netstat -tulpn

to show all the processes on server, and then use kill with the process id . Like kill processid.