DEV Community 👩‍💻👨‍💻

Bobby Bates
Bobby Bates

Posted on

Web Server Kill Process on Ports

Here are a few things you can do when a locally-run web server port is in use and your server won't start back up.

This issue presented itself to me during Phase 3 of Flatiron School: Four weeks of learning Ruby, SQL, Active Record, and Sinatra.

Live or hot reloading all possible things makes me happy, so I was glad to implement rerun on my server immediately after learning about it.

It's great fun to not manually restart a local server on every change in your program, except for this very occasional issue I've come across. This happened when I would tab out of my VS Code window (configured to autosave my app as I leave), which triggers a rerun-fueled refresh in my browser.

I'd often Command + R my webpage anyway to restart my user path, and with the right timing, I would get an error along the lines of port is in use.

My first stop on Google was this Stack Overflow page which gave me a two-step solution: See if any processes were listening to the port my server was on by running:

lsof -i:9292
Enter fullscreen mode Exit fullscreen mode

(ruby was indeed listening to that port, which meant it was blocking my server from restarting on that port), and then run:

kill $(lsof -t -i:9292)
Enter fullscreen mode Exit fullscreen mode

to clear the way for a server restart.

Soon after running into this myself, the same issue came up in class and another solution was shown:

npx kill-port 9292
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.