What is is-port-reachable?
The is-port-reachable npm package is used to check if a port is reachable on a given host. It is useful for network diagnostics and monitoring, allowing developers to programmatically verify if services are accessible over the network.
What are is-port-reachable's main functionalities?
Check port reachability
This feature allows you to check if a specific port on a host is reachable. The function returns a boolean indicating whether the port is open or not.
const isPortReachable = require('is-port-reachable');
(async () => {
const reachable = await isPortReachable(80, {host: 'example.com'});
console.log(reachable); // true or false
})();
Other packages similar to is-port-reachable
portscanner
The portscanner package is similar to is-port-reachable and provides more comprehensive functionality for scanning ports, including checking a range of ports and providing detailed status for each port.
tcp-ping
tcp-ping allows you to perform TCP pings to a server, which includes checking if a port is open. It provides additional information such as latency measurements, which is-port-reachable does not offer.
wait-for-port
wait-for-port is another package that can be used to wait for a port on a host to become available. It is useful for scenarios where you need to wait for a service to start up before performing actions that depend on that service.
is-port-reachable
Check if a local or remote port is reachable
Install
npm install is-port-reachable
Usage
import isPortReachable from 'is-port-reachable';
console.log(await isPortReachable(80, {host: 'google.com'}));
API
isPortReachable(options)
Returns Promise<boolean>
for whether the port is reachable.
port
Type: number
The port to check.
options
Type: object
host
Required
Type: string
Example: 'localhost'
The host to check.
Can be a domain (optionally, with a sub-domain) or an IP address.
timeout
Type: number
Default: 1000
The time to wait in milliseconds before giving up.
Related