Skip to content

vvagaytsev/get-port-please

 
 

Repository files navigation

πŸ”Œ get-port-please

Get an available TCP port to listen

npm version npm downloads License JSDocs

Usage

Install package:

npm i 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

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

About

πŸ”Œ Get an available open port

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%