How can I remove the current process/application which is already assigned to a port?
For example: localhost:8080
In Windows PowerShell version 1 or later to stop a process on port 3000 type:
Stop-Process (,(netstat -ano | findstr :3000).split() | foreach {$[$.length-1]}) -Force
As suggested by @morganpdx here`s a more PowerShell-ish, better version:
Stop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force
One line solution using GitBash:
tskill `netstat -ano | grep LISTENING | findstr :8080 | sed -r 's/(\s+[^\s]+){4}(.*)/\1/'`
Replace 8080 with the port your server is listening to.
If you need to use it often, try adding to your ~/.bashrc
the function:
function killport() {
tskill `netstat -ano | findstr LISTENING | findstr :$1 | sed -r 's/^(\s+[^\s]+){4}(\d*)$/\1/'`
}
and simply run
killport 8080