npm.io
0.0.2 • Published 3 years ago

scotty-beam-me-up

Licence
MIT
Version
0.0.2
Deps
0
Size
24 kB
Vulns
0
Weekly
0

cover npm version npm downloads bundle License

scotty-beam-me-up

Get an available TCP port to listen

npm version npm downloads License [![JSDocs][jsdocs-src]][jsdocs-href]

Usage

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

Options

interface GetPortOptions {
   name?: string

   random?: boolean
   port?: number
   portRange?: [from: number, to: number]
   ports?: number[]
   host?: string

   memoDir?: string
   memoName?: string
}
name

Unique name for port memorizing. Default is default.

random

If enabled, port and ports will be ignored. Default is false.

ļø port

First port to check. Default is process.env.PORT || 3000

ļøļø ports

Extended ports to check.

portRange

Extended port range to check.

alternativePortRange

Alternative port range to check as fallback when non of the ports are available. Default is [3000, 3100] (only when port in unspecified.)

host

The host to check. Default is process.env.HOST otherwise all available hosts will be checked.

License

MIT - Made with