port-get
Version:
Get an available TCP port (a minimal CJS module)
58 lines (35 loc) • 952 B
Markdown
> Get an available TCP port (a minimal CJS module)
## Install
```sh
npm install port-get
```
## Usage
```js
const portGet = require('@holepunchto/port-get')
async function run () {
console.log('here is a port', await portGet())
}
run.catch(console.error)
```
Provide a port list. If all ports are unavailable will pick another port.
```js
const portGet = require('@holepunchto/port-get')
async function run () {
console.log('here is a port', await portGet([7777, 7779, 7779]))
}
run.catch(console.error)
```
Defaults to providing port on host `127.0.0.1`, set host
```js
const portGet = require('@holepunchto/port-get')
async function run () {
console.log('here is any public port', await portGet('0.0.0.0'))
console.log('here is a target public port', await portGet([7777, 7779, 7779], '0.0.0.0'))
}
run.catch(console.error)
```
* https://github.com/sindresorhus/get-port
BSD-3-Clause