'Nodemon EADDRINUSE error every time I save

When using Nodemon I keep getting the EADDRINUSE error telling me the port is currently in use elsewhere even though it isn't.

This error shows up almost every time I save a file, but after I press save again (or twice) it clears up, and the program runs as normal.

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::8800
    at Server.setupListenHandle [as _listen2] (net.js:1318:16)
    at listenInCluster (net.js:1366:12)
    at Server.listen (net.js:1452:7)
    at Function.listen (/home/jake/Documents/Dev/Node-REST-API/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/home/jake/Documents/Dev/Node-REST-API/index.js:31: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:1345:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 8800
}
[nodemon] app crashed - waiting for file changes before starting...
"dependencies": {
    "bcrypt": "^5.0.1",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "helmet": "^4.6.0",
    "mongoose": "^6.0.12",
    "morgan": "^1.10.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.14"
  }

It's just an annoyance. Is there something I can do to fix it?



Solution 1:[1]

I had the same issue, but only when using nodemon in combination with dotenv.

Removing the require("dotenv").config(); at the top of my file did prevent nodemon from crashing after a save, but as you might guese this creates another issue using your env.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eltongonc