Nodejs address already in use :::5000

Viewed 3765

I am trying to run a nodes app. I run node app.js. When I do, I get this error:

node:events:346
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1311:16)
    at listenInCluster (node:net:1359:12)
    at Server.listen (node:net:1446:7)


Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1338:8)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 5000
}

I spent hours looking at possible solutions online but none have worked so far. Same codebase works great on a different machine. This error happens on Mac M1 chip.

Does anybody have any idea how to fix this?

I tried finding processes running on 5000, I tried to kill them etc... nothing worked so far. I am running node 15.14.0.

I am on a M1 Chip, running macOS Monterey

How can I fix this error?

5 Answers

You should disable AirPlay on your mac. Because macOS Monterey started to listen to port 5000 and 8000.

System Preferences > Sharing > untick AirPlay Receiver

Lee Jeonghyun was correct. The reason why kill -9 PID would never work is because of this:

https://developer.apple.com/forums/thread/682332

Control Center on Monterey is listening on 5000 as well.

I changed the port number in my nodejs app and the app started working again.

This also happened to me after upgrading to macOS Monterey from Big Sur.

Every port that I passed to my Node app appeared to be already in use.

You need to disable AirPlay on your mac.

System Preferences > Sharing > untick AirPlay Receiver

Screenshot

List all process on mac:

sudo lsof -PiTCP -sTCP:LISTEN

You will see a list of process and its ports. Choose the process PID on 5000 port or any other port in the error: EADDRINUSE: address already in use...

Finally kill it if it is not an important app for you

kill -9 1234

Did some investigation and found that macOS Monterey is using 5000 port for Airplay-Receiver. If you really want to use the port, then disable that feature in "System Preferences->Sharing".

Below medium post helped me: Port 5000 already in use — MacOS Monterey issue

enter image description here

Related