The process is pretty easy. While your localhost server is working, you have to insert a command in the terminal that looks like this:
npx kill-port 3000
Of course, replace the 3000 with the PORT number that your server is using.
After you run this command, the terminal will ask you to download a small package. You just confirm it, and your local host will be turned off.