get-port-please
TypeScript icon, indicating that this package has built-in type declarations

3.1.2 • Public • Published

🔌 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?: [fromInclusive: number, toInclusive: 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.

The range's start and end are inclusive, i.e. it is [start, end] in the mathematical notion. Reversed port ranges are not supported. If start > end, then an empty range will be returned.

alternativePortRange

Alternative port range to check as fallback when none of the ports are available.

The range's start and end are inclusive, i.e. it is [start, end] in the mathematical notion. Reversed port ranges are not supported. If start > end, then an empty range will be returned.

The default range is [3000, 3100] (only when port is unspecified).

host

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

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.1.21,252,467latest

Version History

VersionDownloads (Last 7 Days)Published
3.1.21,252,467
3.1.1126,226
3.1.02
3.0.30
3.0.21,504
3.0.194,169
2.6.1136,099
2.6.04
2.5.013,047
2.4.33,306
2.4.2714
2.4.12
2.4.00
2.3.01,133
2.2.025,278
2.1.057
2.0.00
1.1.011,423
1.0.014,899
0.0.60

Package Sidebar

Install

npm i get-port-please

Weekly Downloads

1,602,691

Version

3.1.2

License

MIT

Unpacked Size

24.6 kB

Total Files

8

Last publish

Collaborators

  • pi0