node.jsreactjs

Port 5000 in use constantly


So, i've just dealt with this. But I need to figure this out I keep getting

EADDRINUSE :::5000

server.js snippet

const port = process.env.PORT || 5000;
var server = app.listen(port, () =>
  console.log(`Server running on port ${port}`)
);

If I run command sudo lsof -i tcp:5000 I get the following:

node    16476 jedi   59u  IPv4 0x5494461608a39abb      0t0  TCP localhost:62154->localhost:commplex-main (ESTABLISHED)
node    16499 jedi   12u  IPv6 0x54944615f7c1134b      0t0  TCP *:commplex-main (LISTEN)
node    16499 jedi   15u  IPv6 0x54944615f724ee0b      0t0  TCP localhost:commplex-main->localhost:62154 (ESTABLISHED)

I've dealt with this by killing the node processes every time, but that's annoying. How can I figure out what is causing this conflict? I am running my Node server and React environment concurrently. And I noticed when I run the Node independently I do not get the error. I have a proxy setup in my package.json

"proxy": "http://localhost:5000"

I changed the ports and still get the error. Any suggestions?


Solution

  • looks like it's a macOS issue - someone has a solution here - TLDR is go into sharing in your system prefereces and uncheck Airplay Receiver, as Airplay receiver is using that port