Portess
Port and process management
This library helps to find open ports and monitor, find and manage process states.
Installation
npm install --save portess
API
portess.port.isOpen(port)
Finds if the port is open. Return value will be a promise that will be yielded with a boolean result.
const portess = ; await portessport; // true/false /***************(or)**************/ portessport ;
portess.port.get(?[ports])
Get a random open port (or) first available port from the given list. Retuns a promise that will be yielded with a port number.
const portess = ; await portessport; // Returns random port number - ex: 44450await portessport; // Returns first available port from the given list- ex: 3010 (if 3000 is in use) /***************(or)**************/ portessport ; portessport ;
portess.process.isRunning(pid)
Identifies if a process state is active. Returns boolean
const portess = ; portessprocess; // true if the process is running
portess.process.kill(pid)
Kill a process by pid
const portess = ; portessprocess; // false : If the process is not found
portess.monitor(ports...)
Monitor is an EventEmitter
that emits open
when a monitored port is available and close
when the port has closed.
var portess = ;var monitor = 88889999 8082; monitor; monitor; ;
CLI
You can use portess
as a command line utility. You just have to install it globally as npm install -g portess
and run help command portess --help
to find the options and usage.
Usage: portess [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
isOpen|o <port> Find if a port is open or closed
get|g Get an available port
isRunning|r <pid> Find if a process is active or not
kill|k <pid> Kill a process by pid
monitor|m <ports...> Monitor a list of ports and logs to the terminal when port state had changed