Port 3000 needs no introduction. It's the default port for most web servers including your favourite frameworks. Once you lose your developer virginity, there is no escape; port 3000 will always pop up.
So, a process runs on a port. A port can only accommodate one process at a time. A previously occupied port becomes available once the process taking up that space concludes its operation or the process is terminated.
Your machine reminds you of this every time it blasts the Server Error: this port is already in use
message or a similar one across your terminal.
Server Error: this port is already in use
Thankfully, most tools that need to listen to a port gracefully handle port unavailability. For example, NextJs will attempt to run on 3000
, if occupied it will revert to3001
and so on.
Our mission: Let's kill port 3000 and set it free
Killing Port 3000
The kill-port
package is the perfect port assassin.
# Kill a single port
npx kill-port [PORT]
# Kill multiple ports
npx kill-port [PORT1] [PORT2] [PORTN]
Running any of the commands above terminates the process on the port passed into [PORT]
and you can send multiple ports to their death using the second variant.
You might find several ways to kill ports on Google but I promise you; none is more declarative and self-explanatory than the version I showed you.
I hope this helps you, Port Killer.