Search code examples
javascriptnode.jsmongodbnpmmern

ERROR with npm start. Error: listen EADDRINUSE: address already in use :::5000


this may be the exact same problem for me:MongoDB/React Error: listen EADDRINUSE: address already in use :::5000

I tried the method "npx kill-port 5000", and it says "Process on port 5000 killed". However, I run "npm start" again, it just gives me the same error.

here's my server index.js

import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";

const app = express();

app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());

const CONNECTION_URL = 'mongodb+srv://weiz:[email protected]/?retryWrites=true&w=majority';
const PORT = process.env.PORT || 5000;

mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
    .then(() => app.listen(PORT, () => console.log("Server running on port: 5000"))) //useless
    .catch((error) => console.log(error.message));


mongoose.connect(CONNECTION_URL).then(() => { console.log('...') });

here's my error

apple@3 server % npm start

> [email protected] start
> nodemon index.js

[nodemon] 2.0.16
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
...
node:events:505
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1372:16)
    at listenInCluster (node:net:1420:12)
    at Server.listen (node:net:1508:7)
    at Function.listen (/Users/apple/Desktop/memories_project/server/node_modules/express/lib/application.js:635:24)
    at file:///Users/apple/Desktop/memories_project/server/index.js:23:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1399:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 5000
}
[nodemon] app crashed - waiting for file changes before starting...

if more codes need to be provided, I will add them.


Solution

  • I finally solved this by updating my mac system. I think there must be some problem with my airplay function in the old system version