Intro

You’re working on web project and boot it up on a local host to see how it’s working. You go to the specified port but find that the port is already in use, as its been left running unknowingly.

This is an issue I’ve encountered numerous times. One option is to just use a new port, though that may require some tampering, and if the given port is required to be set to a specified port number in order to adher to the opinions of a hosting service (typically 8080), and you forget to switch it back, it may stop your app from being able to be deployed. Here is a quick fix to deal with the situation.

Fix

Assuming we are using macOS, below are the steps to follow.

We get this message:

port [ e.g. 3000] already  in use

To close the port we can do the following:

sudo lsof -i :3000

We get a return with the PID.

We then run:

kill -9 [PID]

And presto, the port is now available for use.