eaddrinuse address already in use nodejs

Hi Guy’s Welcome to Proto Coders Point. This NodeJS article is on solving a commonly faced error while working with nodejs application “listen EADDRINUSE: Address already in use – NodeJS”.

5 Common Cat Behaviours And What Th...
5 Common Cat Behaviours And What They Mean

The Error we get

When working with nodejs + Express.js that works on particular port number, and you see an error “Address already in use”

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

This simply means that port number 3000 is already in used by some other program or application, and thus can’t us the same port.

Here is the full error message that you get:

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
}

As I said port 3000 is been used by some other program.

Solution for : EADDRINUSE: address already in use

Solution 1 : Change port number of current nodejs express server application

In current nodejs application that you are trying to run you can simply change the port address from 3000 to someother port (3001), thus your application will run prefectly.


Solution 2 : npx kill port

You need to stop the program that is been running on port number 3000.

Sometimes you will not be able to find the program that is running on port 3000, This happens when the nodejs crashes in background but is till utilizing the port.

You need to simply kill the port that is running

Execute the below command:

npx kill-port 3000

Here if you want to free up unused port (multiple port) that are running then use the command as below

npx kill-port 3001 3002 5010 6100 8080

If non of the above works for you, then solution 3 will definitely work


Solution 3: Simple restart your computer

Just restart your pc/laptop and the used address port will automatically get killed or free.