pid-port
Get the process ID for the process that uses a certain port
Install
$ npm install pid-port
Usage
const pidPort = require('pid-port');
(async () => {
try {
console.log(await pidPort.portToPid(8080));
const pids = await pidPort.all([8080, 22]);
console.log(pids.get(8080));
console.log(pids.get(22));
} catch (error) {
console.log(error);
}
})();
API
pidPort.portToPid(port)
port
Type: number
Port to look up.
pidPort.all(ports)
Returns a Promise<Map<number, number>>
with the port as key and the process ID as value.
ports
Type: number[]
Ports to look up.
pidPort.list()
Get all process IDs from ports.
Returns a Promise<Map<number, number>>
with the port as key and the process ID as value.