is-port-reachable
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -1,15 +0,17 @@ | ||
interface Options { | ||
export interface Options { | ||
/** | ||
Milliseconds to wait before giving up. | ||
The host to check. | ||
@default 1000 | ||
Can be a domain (optionally, with a sub-domain) or an IP address. | ||
@example 'localhost' | ||
*/ | ||
timeout?: number; | ||
readonly host: string; | ||
/** | ||
Can be a domain or an IP. | ||
The time to wait in milliseconds before giving up. | ||
@default 'localhost' | ||
@default 1000 | ||
*/ | ||
host?: string; | ||
readonly timeout?: number; | ||
} | ||
@@ -24,9 +26,6 @@ | ||
if(await isPortReachable(3000)) { | ||
// start server | ||
} | ||
console.log(await isPortReachable(80, {host: 'google.com'})); | ||
//=> true | ||
``` | ||
*/ | ||
declare function isPortReachable(port: number, options?: Options): Promise<boolean>; | ||
export = isPortReachable; | ||
export default function isPortReachable(port: number, options: Options): Promise<boolean>; |
13
index.js
@@ -1,5 +0,8 @@ | ||
'use strict'; | ||
const net = require('net'); | ||
import net from 'node:net'; | ||
module.exports = async (port, {timeout = 1000, host} = {}) => { | ||
export default async function isPortReachable(port, {host, timeout = 1000} = {}) { | ||
if (typeof host !== 'string') { | ||
throw new TypeError('Specify a `host`'); | ||
} | ||
const promise = new Promise(((resolve, reject) => { | ||
@@ -26,5 +29,5 @@ const socket = new net.Socket(); | ||
return true; | ||
} catch (_) { | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
} |
{ | ||
"name": "is-port-reachable", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Check if a local or remote port is reachable", | ||
"license": "MIT", | ||
"repository": "sindresorhus/is-port-reachable", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
@@ -15,4 +16,6 @@ "contributors": [ | ||
], | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -44,6 +47,6 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"xo": "^0.25.3", | ||
"tsd": "^0.17.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -5,32 +5,29 @@ # is-port-reachable | ||
## Install | ||
```sh | ||
npm install is-port-reachable | ||
``` | ||
$ npm install is-port-reachable | ||
``` | ||
## Usage | ||
```js | ||
const isPortReachable = require('is-port-reachable'); | ||
import isPortReachable from 'is-port-reachable'; | ||
(async () => { | ||
console.log(await isPortReachable(80, {host: 'google.com'})); | ||
//=> true | ||
})(); | ||
console.log(await isPortReachable(80, {host: 'google.com'})); | ||
//=> true | ||
``` | ||
## API | ||
### isPortReachable(port, options?) | ||
### isPortReachable(options) | ||
Returns `Promise<boolean>`. | ||
Returns `Promise<boolean>` for whether the port is reachable. | ||
#### port | ||
##### port | ||
Type: `number` | ||
The port to check. | ||
#### options | ||
@@ -42,7 +39,10 @@ | ||
**Required**\ | ||
Type: `string`\ | ||
Default: `'localhost'` | ||
Example: `'localhost'` | ||
Can be a domain or an IP. | ||
The host to check. | ||
Can be a domain (optionally, with a sub-domain) or an IP address. | ||
##### timeout | ||
@@ -53,7 +53,6 @@ | ||
Milliseconds to wait before giving up. | ||
The time to wait in milliseconds before giving up. | ||
## Related | ||
- [is-reachable](https://github.com/sindresorhus/is-reachable/) - Check if servers are reachable |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
4003
49
0
Yes
56