question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: listen EADDRINUSE: address already in use :::5000

See original GitHub issue
  • nodemon -v: 2.0.7
  • node -v: 14.16.01
  • Operating system/terminal environment: MacOS Big Sur
  • Using Docker? No
  • Command you ran: nodemon server

Expected behaviour

Close port before reinitializing server.

Actual behaviour

[0] [nodemon] starting `node server.js`
[0] events.js:292
[0]       throw er; // Unhandled 'error' event
[0]       ^
[0] 
[0] Error: listen EADDRINUSE: address already in use :::5000
[0]     at Server.setupListenHandle [as _listen2] (net.js:1318:16)
[0]     at listenInCluster (net.js:1366:12)
[0]     at Server.listen (net.js:1452:7)
[0]     at Function.listen (/Users/tf/Documents/courses/MERN/server/node_modules/express/lib/application.js:618:24)
[0]     at Object.<anonymous> (/Users/tf/Documents/courses/MERN/server/server.js:35:5)
[0]     at Module._compile (internal/modules/cjs/loader.js:1063:30)
[0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
[0]     at Module.load (internal/modules/cjs/loader.js:928:32)
[0]     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
[0]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
[0]     at internal/main/run_main_module.js:17:47
[0] Emitted 'error' event on Server instance at:
[0]     at emitErrorNT (net.js:1345:8)
[0]     at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EADDRINUSE',
[0]   errno: -48,
[0]   syscall: 'listen',
[0]   address: '::',
[0]   port: 5000
[0] }
[0] [nodemon] app crashed - waiting for file changes before starting...

Steps to reproduce

  1. Initialize app (basic MERN app)
  2. Save any file.
  3. Error is thrown.

This only started happening after I updated my Mac to Big Sur. I can circumvent this issue by either stopping the app and killing the port or by saving a second time a couple of seconds after the first crashed the server.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
roshennaircommented, Apr 14, 2021

I’ve found a temporary work-around, the steps for which are listed below:

  1. Install the NPM kill-port package as a development dependency: npm install -D kill-port
  2. Create a new file in your project’s root directory called nodemon.json and paste in the following JSON (edit the port numbers below from 3000 to whatever port you’re using for your Node.js app):
{
	"events": {
		"restart": "kill-port 3000",
		"crash": "kill-port 3000"
	 },
	"delay": "1500"
}
  1. Add the following NPM script to your package.json file (if you haven’t already):
"scripts": {
	"dev": "nodemon app.js",
},

All credit goes to Tudor Constantin on Stack Overflow. However, it is a bit tedious and definitely a workaround, not something that should be done for all future Node.js projects.

12reactions
remycommented, Apr 13, 2021

Okay, start striping the code back until you have the bare minimum and you can still replicate, then post that here, then we can take a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node / Express: EADDRINUSE, Address already in use - Kill ...
First, you would want to know which process is using port 3000 sudo lsof -i :3000. this will list all PID listening on...
Read more >
How to kill server when seeing “EADDRINUSE: address ...
Nodejs listen EADDRINUSE: address already in use. The Problem. When trying to restart a Node application, the previous one did not shut down ......
Read more >
Node.js Error: listen EADDRINUSE: Address already in use
This quick article shows you how to solve a common error you might confront when working with Node.js. The Problem When developing a...
Read more >
Node.js – listen EADDRINUSE: address already in use :::5000
Node.js – listen EADDRINUSE: address already in use :::5000. node.jsnpm. In my application, I use concurrently to run both backend and front end ......
Read more >
How To Solve "EADDRINUSE - Address Already In Use"
If you ever run into this problem, you have 2 options: Run your application on a different port, or; Terminate the existing process....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found