RepoPilot

Can I bind to a specific host? How is the host option passed through?

About sindresorhus/get-port · 2 messages · last activity 6/15/2026

Question

Can I bind to a specific host? How is the host option passed through?

RepoPilot

Yes, you can bind to a specific host using the host option. Here's how it works:

Host Option Usage

The host option is passed directly in the options object:

import getPort from 'get-port';

console.log(await getPort({host: '127.0.0.1'}));

According to the documentation, the host option can be either an IPv4 or IPv6 address. When set, the library will only check availability on that specific host rather than checking all local addresses [index.d.ts:L29-L36].

How It's Passed Through

The host option is passed through to the underlying Node.js server listening mechanism. In the main function [index.js:L89-L168], the options are destructured to extract reserve, and the remaining options (including host) are spread into netOptions:

const {reserve, ...netOptions} = options ?? {};

These netOptions are then passed to getAvailablePort() [index.js:L145], which in turn passes them to checkAvailablePort() [index.js:L47-L60]. The checkAvailablePort function uses these options directly when calling server.listen(options, ...) [index.js:L54].

This means the host option flows directly into Node.js's native net.Server.listen() method, which handles the actual binding.

FOLLOW_UPS:

  • What happens if host is omitted?
  • Can you use both host and port together?
  • Does host affect the reserve option behavior?

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.