$ cnpm install get-port-please

Get an available TCP port to listen
Install package:
yarn add get-port-please
# 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 > 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. Default is [3000, 3100]
hostThe host to check. Default is process.env.HOST otherwise all available hosts will be checked.
MIT
Copyright 2013 - present © cnpmjs.org | Home |