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

Preferred port range? #24

Closed
tiagosiebler opened this issue Nov 2, 2018 · 10 comments
Closed

Preferred port range? #24

tiagosiebler opened this issue Nov 2, 2018 · 10 comments
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted

Comments

@tiagosiebler
Copy link

tiagosiebler commented Nov 2, 2018

Issuehunt badges

Would be nice to see an option to provide a preferred range, rather than array of ports.

console.log(
  await getPort({port: 
    { 
      from: 4000,
      to: 5000
    }
  })
);

stroncium earned $30.00 by resolving this issue!

@tiagosiebler
Copy link
Author

tiagosiebler commented Nov 2, 2018

Lil snippet that helps, in case you want to make this a feature:

const getNumberRange = (start, end) => Array.from({length: (end - start)}, (v, k) => k + start);
(async () => {
  const numberRange = getNumberRange(4000, 6000);
  console.log(await getPort({port: numberRange}));
})();

@acostalima
Copy link
Contributor

I fail to see a use case where one would try to find an available port in a range of 1000+ ports, but I might be missing something. Anyhow, I think the array argument should do just fine for most scenarios. If you really need to target a specific range, you can provide it yourself just like in the example above.

@sindresorhus?

@kevva
Copy link

kevva commented Nov 2, 2018

Anyhow, I think the array argument should do just fine for most scenarios. If you really need to target a specific range, you can provide it yourself just like in the example above.

I agree. Accepting an array like we do now is sufficient enough.

@sindresorhus
Copy link
Owner

@tiagosiebler What's your use-case for needing ports in a specific range?

@tiagosiebler
Copy link
Author

@sindresorhus distributed nodejs workers, each of which may be running a long-term task. New task = new worker, so it's never sure how many I'll need on each server.

Each worker exposes a dedicated REST API, but may not be running as a root user. I'm not sure if this lib might accidentally give a privileged port that requires root to open or how that kind of clash is handled. I'd rather just provide a larger range outside any normally used ports (30k->35k). The array generator above works fine for my needs, just thought I'd throw it out here in case you see value in adding it in as a feature.

@HaykoKoryun
Copy link

@acostalima we maintain a large number of components and sometimes need to work on several of them at the same time. Each component spins up a small local web server for it's demo (with all possible configurations). Since we will never go above say 200 components, it would be easy to declare a range from 3000 to 3200 and leave it at that.

@sindresorhus
Copy link
Owner

I don't want to overload the port option with another value type, but maybe we could expose a getPort.makeRange(from, to) method for convenience. The benefit of having it as a method is that it's more flexible. You could combine ranges or filter out some specific ports from the range.

It should throw an error if the from argument is lower than 1024, as those are system/well-known ports.

@r0mflip
Copy link

r0mflip commented Mar 18, 2019

This can be really helpful when you try to find a useful port in a given range. A good example would be, Spotify [used to] listens on a specific port in range(say, from 6540 to 6550 something), the widget player in browser sends a request to 127.0.0.1:6540 upto 6550 and connects to the system app installed, controlling it.

I also found this feature required on a project of mine, where I tried to do the same thing as Spotify but settled for 3 ports in sequence, than 10 ports because I didn't want a ton of constants. Maybe useful 🤷‍♂️

@IssueHuntBot
Copy link

@IssueHunt has funded $30.00 to this issue.


stroncium added a commit to stroncium/get-port that referenced this issue Mar 24, 2019
sindresorhus added a commit that referenced this issue Apr 5, 2019
Fixes #24 


Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@IssueHuntBot
Copy link

@sindresorhus has rewarded $27.00 to @stroncium. See it on IssueHunt

  • 💰 Total deposit: $30.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $3.00

@issuehunt-oss issuehunt-oss bot added the 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt label May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted
Projects
None yet
Development

No branches or pull requests

7 participants