0

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...
Community
  • 1
  • 1
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
  • It looks like `npm start` is starting the server on port 3000, and your debugger config is also launching the server on port 3000. I don't understand the problem with just using the debugger launch - what else does `npm start` do? – Rob Lourens Dec 24 '16 at 18:12

1 Answers1

0

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.

Shekhar Tyagi
  • 1,644
  • 13
  • 18
  • can u show me what it shows when you type this command 'netstat -tulpn' in terminal – Shekhar Tyagi Dec 20 '16 at 08:10
  • I got it showing all the processes using port 3000 by doing `lsof -n -i4TCP:3000`. It just showed that the debugger runs port 3000 as it'll have nothing using that port, then I start the debugger and something is using that port. Regarding your answer it says `sh-3.2# netstat -tulpn netstat: n: unknown or uninstrumented protocol sh-3.2#` – BeniaminoBaggins Dec 20 '16 at 08:17
  • if you found any process related to port 3000 then kill or stop that process. i think it works after that. – Shekhar Tyagi Dec 20 '16 at 09:06
  • can you do onething , just try to change the port no of your app. – Shekhar Tyagi Dec 20 '16 at 09:26
  • Yep I just posted what happened to the bottom of my question. Cheers – BeniaminoBaggins Dec 21 '16 at 03:43