The following interface would be useful for safely determining port numbers for your services.
type PortNumber = number | string
// Throw an error if the given `port` number is already in use
declare function assertPortFree(port: PortNumber): void
// Returns an array of port numbers that are not in use.
declare function findPorts(numberOfPorts: number, options: { exclude: PortNumber | PortNumber[] }): number[]
// Example of using findPorts
const [apiPort, webPort] = findPorts(2, { exclude: PORT });
The function signatures above assume that we're only ever working with ports on localhost.
Should we support working with ports on other hosts?
Docker Machine runs on a different host than localhost on Windows, for example.
The following interface would be useful for safely determining port numbers for your services.
The function signatures above assume that we're only ever working with ports on
localhost.Should we support working with ports on other hosts?
Docker Machine runs on a different host than
localhoston Windows, for example.