Node.js Error: listen EADDRINUSE: Address already in use

Updated: September 14, 2022 By: A Goodman 2 comments

This quick article shows you how to solve a common error you might confront when working with Node.js.

The Problem

When developing a Node.js application (with Express.js), I sometimes fall into the following problem:

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

Full error message:

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1380:16)
    at listenInCluster (node:net:1428:12)
    at Server.listen (node:net:1516:7)
    at Function.listen (/Users/goodman/Desktop/Projects/kindacode/api/node_modules/express/lib/application.js:635:24)
    at server (/Users/goodman/Desktop/Projects/kindacode/api/src/index.ts:60:7)
    at bootstrap (/Users/goodman/Desktop/Projects/kindacode/api/src/index.ts:73:3)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 3000
}

The console message indicates that I am trying to run my app with a port being used by some program. This happens after my app crashes. Behind the scene, it’s very likely that there is a terminal window hiding out in the background that is still running the app. If you encounter the same problem as mine, don’t panic. Below is the solution.

The Solution

What we have to do is really simple: kill the process that is running on the port. Execute the command below:

npx kill-port 3000

If you need to free a port other than 3000, run the command above on that port. It’s also possible to terminate multiple ports at once:

npx kill-port 3000 4000 5000 6000 7000

Another solution that can solve this problem, as well as many others, is just restarting your computer (you even don’t have to do that in this situation).

That’s it. Further reading:

You can also check out our Node.js category page for the latest tutorials and examples.

Subscribe
Notify of
guest
2 Comments
Inline Feedbacks
View all comments
depa
depa
1 year ago

thank you so much, this is really helpful for a new developer

anton
anton
1 year ago

Thank you, everyone else on every other forum gave complex answers, yours made the most sense and worked. I had another terminal open and I didn’t even notice.

Related Articles