nodemon giving this error code: 'EADDRINUSE', errno: -4091, syscall: 'listen', address: '::', port: 5000

Viewed 1870
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1347:8)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 5000
}
[nodemon] app crashed - waiting for file changes before starting...
2 Answers

Having the same problem but I have 3 fixes for this you can use any

  • 1. a permanent and long way:

    • i. Install the kill-port node package as a dev dependency:

      npm install kill-port --save-dev
      
    • ii. Create a nodemon.json file in the root of your project containing:

      {
        "events": {
        "restart": "kill-port 5000",
        "crash": "kill-port 5000"
       },
      "delay": "1500"
      }
      
    • iii. Then, in your package.json file, have something like this:

      "scripts": {
      "start-dev": "nodemon app.js",
      }
      
    • iv. Then start your app in dev mode with:

       npm run start-dev
      
  • 2. Manually kill from the system(easy fix):

    directly kill the port with the following command.

    fuser -n tcp -k 5000
    
  • 3. Restarting the system:

    • restarting the project
    • restarting the computer

For windows

netstat -ano | findstr : 5000
(output : TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 18264)
taskkill /PID 18264 /f

Mainly this error comes when we run our code on same port or port already busy, so we have to kill the process

For ubuntu

fuser -k 5000/tcp
Related