Skip to content

nyxblabs/scotty-beam-me-up

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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 ๐Ÿ’ž

About

๐Ÿ›ธ Get an available TCP port to listen

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project