fallback-port
v0.1.7
Published
get an available port and preventing eaddrinuse error.
Downloads
42
Maintainers
Readme
fallback-port
get an available port and preventing eaddrinuse error.
If multiple applications running same port then you will get the below error (Error: listen EADDRINUSE)
.
This module will give you an available port and kill other processes.
This module covered Mac OSX and Windows.
Install
$ npm install fallback-port
API
getPid
Finding the PID from default port.
return pid number or null.
getPort
Tries return a random available port if the requested port is taken
kill
Find and kill process locking port.
Example
var port = 8080;
var fallbackPort = new FallbackPort(8080);
//return pid number or null
var pid = fallbackPort.getPid();
//return available port
var otherPort = fallbackPort.getPort();
if(otherPort != port){
console.log( `${port} is taken` )
}
//kill process
fallbackPort.kill();