|
|
3 years ago | |
|---|---|---|
| .. | ||
| dist | 3 years ago | |
| LICENSE | 3 years ago | |
| README.md | 3 years ago | |
| package.json | 3 years ago | |
Get an available TCP port to listen
Install package:
yarn add get-port-please
# or
or npm install get-port-please
// ESM
import { getPort, checkPort, getRandomPort, waitForPort } from 'get-port-please'
// CommonJS
const { getPort, checkPort, getRandomPort, waitForPort } = require('get-port-please')
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 > memo > random
interface GetPortOptions {
name?: string
random?: boolean
port?: number
portRange?: [from: number, to: number]
ports?: number[]
host?: string
memoDir?: string
memoName?: string
}
nameUnique name for port memorizing. Default is default.
randomIf enabled, port and ports will be ignored. Default is false.
portFirst port to check. Default is process.env.PORT || 3000
portsAlternative ports to check.
portRangeAlternative port range to check. Deefault is [3000,3100]
hostThe host to check. Default is process.env.HOST otherwise all available hosts will be checked.
memoDir / memoNameOptions passed to fs-memo
node_modules/get-port/dist.get-portMIT