RepoPilot

What is the type signature of the main exported function?

About sindresorhus/get-port · 2 messages · last activity 5/25/2026

Question

What is the type signature of the main exported function?

RepoPilot

The main exported function getPort has the following type signature, defined in [index.d.ts:L66]:

export default function getPort(options?: Options): Promise<number>;

It accepts an optional Options object and returns a Promise that resolves to a number representing the available TCP port.

The Options type is defined in [index.d.ts:L3-L65] and includes the following properties:

  • portnumber | Iterable<number> — A preferred port or iterable of preferred ports
  • excludeIterable<number> — Ports that should not be returned
  • reserveboolean (default: false) — Reserve the port for the lifetime of the process
  • hoststring — The host on which port resolution should be performed

The Options type also extends Omit<ListenOptions, 'port'>, which allows additional Node.js server listen options like ipv6Only.

FOLLOW_UPS:

  • How does the exclude option work internally?
  • What happens when a port is reserved vs. not reserved?
  • How does portNumbers() helper function work?

Want to ask your own question?

Open chat for sindresorhus/get-port

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/get-port. AI answers can be incomplete or stale — verify before relying on them.