Kill any process running on a given TCP port on Windows, Linux or Mac
$ npm install cross-port-killer -D
import { kill, killer } from 'cross-port-killer';
kill(9090).then(pids => {
console.log(pids)
})
// you could also kill pids manually if you know them... this would save you bringing up another lib, you are welcome.
killer.killByPid(12345).then(() => console.log('done'))
killer.killByPids([12345, 54321]).then(() => console.log('done'))
This lib also comes with a CLI
.
To kill any process occupying the port 9090 you can run:
$ npx cross-port-killer 9090
or
$ npm install cross-port-killer -g
$ kill-port 9090
On Linux/Mac this library depends on lsof
in case you don't have it installed (perhaps you are using docker?) run:
$ apt install lsof
On Mac, It comes with the OS by default so nothing to worry.