Frontendroom
Tools
Categories
ShortsAbout
FUNDAMENTAL

How to kill server running at a port in macOS

Problem?

While working with node js project (npm or yarn) in the terminal, sometimes we face a strange problem. Sometimes even if we close the server in terminal, still it is runing under the hood. When we restart the server again (using npm start or yarn start), it ask for assigning new port.

  1. x
    1. Now Playing
      Up NextHow to Run Php Projects in Xampp
    2. Now Playing
      Up NextLimiteds vs a Really Toxic Server New Journey MNJ Roblox
    3. Now Playing
      Up NextTo Kill a Mockingbird Summary | By Harper Lee To Kill a Mockingbird Audiobook
    4. Now Playing
      Up NextVPN Kill Switch Explained: Why You Need It for Ultimate Online Privacy! | VPN EXPO
    5. Now Playing
      Up NextBuild Your Own Pull-Out Pantry
    6. Now Playing
      Up NextHow to Connect to Remote SSH in VS Code and Transfer Files Over SFTP to VPS Server Full Tutorial
    7. Now Playing
      Up NextHow to SUPER JUMP in Roblox combat warriors ...
    8. Now Playing
      Up NextHow to Setup SFTP Server on Ubuntu 24.04 (Simple Guide)
    9. Now Playing
      Up NextHow to install docker on ubuntu AWS Server
    10. Now Playing
      Up NextWhat Is Port Forwarding Gaming
    11. Now Playing
      Up Nexthow to make a second unturned server
    12. Now Playing
      Up NextSecurity; How should be set an unprotect environment on modern linux to test an old buffer overfl...
    13. Now Playing
      Up NextHow To Build Your Own Home in Don't Starve; Shipwrecked
    14. Now Playing
      Up NextOrganizing Kitchen Cabinets Efficiently
    15. Now Playing
      Up NextHow to draw Sauna Egg from Cookie Run Ovenbreak
    16. Now Playing
      Up NextHow to Clean the USB Port of OPPO A77s Phone using Simple Household Items
    17. Now Playing
      Up NextWhat Is A Dedicated Server In Gaming
x

But we don't want to do that. Under the hood server is occupying that port and we want to use that port.

If you are using mac os, here is quick step to kill the server which is runing under the hood.

Steps to solve this problem

  1. Find the Process ID (PID)

First of all you will need to find the process ID on which that server is running on that specific port.

For example, if server was running at port 8000, you can find the PID using this below command:

sudo lsof -ti :8000

Result:

89711

here, irdmi is basically represents port 8000.

  1. Kill Process ID (PID)

Use this command to kill the process.

kill -9 <PID>

e.g.:

kill -9 89711

That's all.

In single line, you can write command as below

kill -9 $(lsof -ti:<PortNumber>)

e.g.:

kill -9 $(lsof -ti:8000)