How to Fix: EADDRINUSE, Address already in use - Kill server

Better Stack Team
Updated on April 4, 2024

The "EADDRINUSE, Address already in use" error occurs when you try to start a server on a port that is already in use by another process. To fix this issue, you can take the following steps:

Identify the Process Holding the Port

You can use the following command to identify the process that is using the specific port:

lsof -i :<port_number>

Replace <port_number> with the actual port number where you are encountering the "EADDRINUSE" error. This command will show you the process ID (PID) and details of the process using that port.

Kill the Process

Once you identify the PID of the process using the port, you can use the kill command to terminate that process. Replace <PID> with the actual process ID:

kill -9 <PID>

The -9 option sends a SIGKILL signal to forcefully terminate the process.

Restart Your Server

After killing the process, you should be able to restart your server without encountering the "EADDRINUSE" error.


Let's assume your server is running on port 3000, and you encounter the "EADDRINUSE" error:

lsof -i :3000

This will give you information about the process using port 3000. Let's say the PID is 1234:

kill -9 1234

Replace 1234 with the actual PID you obtained from the lsof command.

Automated Approach (Unix-like Systems)

On Unix-like systems (Linux, macOS), you can combine these commands in a one-liner to quickly kill the process using the port:

lsof -i :<port_number> | awk 'NR!=1 {print $2}' | xargs kill -9

Replace <port_number> with your actual port number. This one-liner uses awk to extract the PID and xargs to pass it to the kill command.

After killing the process, you can restart your server on the specified port without encountering the "EADDRINUSE" error.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github