๐ธ Get an available TCP port to listen
[![JSDocs][jsdocs-src]][jsdocs-href]
Install package:
npm i scotty-beam-me-up
// ESM
import {
checkPort,
getPort,
getRandomPort,
waitForPort,
} from 'scotty-beam-me-up'
// CommonJS
const {
getPort,
checkPort,
getRandomPort,
waitForPort,
} = require('scotty-beam-me-up')
getPort(options?: GetPortOptions): Promise<number>
checkPort(port: number, host?: string): Promise<number | false>
waitForPort(port: number, options): Promise<number | false>
Try sequence is: port > ports > random
interface GetPortOptions {
name?: string
random?: boolean
port?: number
portRange?: [from: number, to: number]
ports?: number[]
host?: string
memoDir?: string
memoName?: string
}
Unique name for port memorizing. Default is default
.
If enabled, port
and ports
will be ignored. Default is false
.
First port to check. Default is process.env.PORT || 3000
Extended ports to check.
Extended port range to check.
Alternative port range to check as fallback when non of the ports are available. Default is [3000, 3100]
(only when port
in unspecified.)
The host to check. Default is process.env.HOST
otherwise all available hosts will be checked.
MIT - Made with ๐