RepoPilot

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

About sindresorhus/get-port · 2 messages · last activity 6/8/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. According to the README, the getPort() function accepts a host option in its options object.

From the README excerpt:

host

Type: string

The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.

By default, it checks availability on all local addresses defined in OS network interfaces. If this option is set, it will only check the given host.

So you would pass it like this:

import getPort from 'get-port';

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

Or with IPv6:

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

However, the repository data provided only contains the README excerpt and doesn't include the actual implementation source code. To see exactly how the host option is passed through the internal logic and used during port resolution, you would need to examine the main implementation file directly (likely index.js, index.ts, or similar in the root or src/ directory).

FOLLOW_UPS:

  • How does the library check port availability internally?
  • Can I combine host option with preferred ports?
  • What's the difference between ipv6Only 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.