Find and Kill Processes Locking Specific Ports on a Mac
Problem: Sometimes, when you start a local Node.js server, it may continue running in the background. If you try to start the server again, you may encounter an error indicating that the port (e.g., 8080) is already in use and locked:
Solution: You can use the lsof
command to identify the process locking the port:
Alternatively, you can replace 8080
with the specific port number you want to investigate. This will display a list of processes currently using that port. Identify the process you wish to terminate (for example, node
running with PID 6709
) and execute the following command to kill it:
Finally, restart your server. It should run normally once the port has been freed.