Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Port Utilities" #16

Open
zenflow opened this issue Sep 21, 2020 · 1 comment
Open

Add "Port Utilities" #16

zenflow opened this issue Sep 21, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@zenflow
Copy link
Owner

zenflow commented Sep 21, 2020

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.

@zenflow zenflow added the enhancement New feature or request label Sep 21, 2020
@zenflow zenflow changed the title Add "Port Utilities" (scope: port-utilities) Add "Port Utilities" Mar 18, 2021
@zenflow
Copy link
Owner Author

zenflow commented Mar 19, 2021

Inspiration (or maybe good enough): https://github.com/http-party/node-portfinder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant