0

I have just started a Node js course on Udemy, and I'm stuck in some parts of it. The instructor taught on how to debug, but it apparently seems to not work on my device. When I press the button "Start debugging", and select Node js, I get an error, and it just goes back to where it was. Here's the error if anyone knows about it.

>Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (net.js:1317:16)
    at listenInCluster (net.js:1365:12)
    at Server.listen (net.js:1451:7)
    at Function.listen (c:\Users\maria\OneDrive\Documentos\Miguel\Código\Curso completo Node.js\03_Express\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (c:\Users\maria\OneDrive\Documentos\Miguel\Código\Curso completo Node.js\03_Express\app.js:24:5)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1344:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 3000
}

Thanks to anyone who might help.

1 Answers1

0

If you are on linux try this command:

lsof -i tcp:3000

you will see something like this

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME  
node    12012 user   20u  IPv6  86535      0t0  TCP *:3000 (LISTEN)

Which means a process with PID 12012 already using your port 3000.
You can kill the process by following command:

sudo kill -9 PID

(replace PID with process id, which in my case is 12012).

tripleee
  • 139,311
  • 24
  • 207
  • 268
  • Don't use `kill -9` unless you know what you are doing. Basically, try `kill PID` and `kill -2 PID` and `kill -15 PID` and wait a while, and if the process is still around, *then* bring out the big gun. Killing a process unconditionally doesn't let it do any cleanup, which could lead to file handle leaks and race conditions etc. Or cause the "address already in use" for that matter. – tripleee Jan 15 '21 at 05:38