Sometimes due to multiple use of the port where the localhost server is running gets stuck. the reason is even if you close a localhost server that port is still in use by some process. As a result it will not allow to restart the server.
There are two ways to forcefully clear the port so that you can restart the server again.
#1> In the terminal type:
ps aux | grep <process name>
It will give a list of process with PID of the process.
Then you can directly write
kill -9 <PID>
This is the conventional way of doing it. But there is a quicker way also available for this.
#2> You can directly use
sudo fuser -k <port number>/tcp
It will directly clear the given port number.
Suppose i am running my server on localhost:8008/ so my port is 8008 now.
I can directly use sudo fuser -k 8008/tcp It will directly clear that port and I can restart my server very quickly without getting the PID.