Socket
Socket
Sign inDemoInstall

is-port-reachable

Package Overview
Dependencies
0
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 3.0.0

21

index.js
'use strict';
const net = require('net');
module.exports = (port, options) => {
options = Object.assign({timeout: 1000}, options);
return new Promise((resolve => {
module.exports = async (port, {timeout = 1000, host} = {}) => {
const promise = new Promise(((resolve, reject) => {
const socket = new net.Socket();

@@ -12,14 +10,21 @@

socket.destroy();
resolve(false);
reject();
};
socket.setTimeout(options.timeout);
socket.setTimeout(timeout);
socket.once('error', onError);
socket.once('timeout', onError);
socket.connect(port, options.host, () => {
socket.connect(port, host, () => {
socket.end();
resolve(true);
resolve();
});
}));
try {
await promise;
return true;
} catch (_) {
return false;
}
};
{
"name": "is-port-reachable",
"version": "2.0.1",
"version": "3.0.0",
"description": "Check if a local or remote port is reachable",

@@ -16,3 +16,3 @@ "license": "MIT",

"engines": {
"node": ">=4"
"node": ">=8"
},

@@ -43,5 +43,5 @@ "scripts": {

"devDependencies": {
"ava": "^0.25.0",
"xo": "^0.18.0"
"ava": "^2.4.0",
"xo": "^0.25.3"
}
}

@@ -27,3 +27,3 @@ # is-port-reachable [![Build Status](https://travis-ci.org/sindresorhus/is-port-reachable.svg?branch=master)](https://travis-ci.org/sindresorhus/is-port-reachable)

### isPortReachable(port, [options])
### isPortReachable(port, options?)

@@ -38,8 +38,8 @@ Returns `Promise<boolean>`.

Type: `Object`
Type: `object`
##### host
Type: `string`<br>
Default: `localhost`
Type: `string`\
Default: `'localhost'`

@@ -50,3 +50,3 @@ Can be a domain or an IP.

Type: `number`<br>
Type: `number`\
Default: `1000`

@@ -60,6 +60,1 @@

- [is-reachable](https://github.com/sindresorhus/is-reachable/) - Check if servers are reachable
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc