rand-port

1.0.1 • Public • Published

rand-port

Find a random available port on localhost

Usage

Include the module:

var rp = require('rand-port')

At a minimum rand-port needs a callback. You'll get a random available registered port:

rp(function (port) {
    // port in range [1024, 49151]
})

Pass a multiple of 1000 as the first argument to get a random available port between it and the next multiple of 1000:

rp(3000, function (port) {
    // port in range [3000, 3999]
})

Development

Clone the repository, install dependencies, and test:

git clone https://github.com/pe8ter/rand-port.git
npm install
npm test

The tests aren't perfect because of the module's random behavior. A test failure is always a sign that something's wrong, but the whole suite passing is not necessarily proof that everything is okay. It's a strong signal, just not as strong as I would like it to be.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    4
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    4
  • 1.0.0
    1
  • 0.0.0
    1

Package Sidebar

Install

npm i rand-port

Weekly Downloads

4

Version

1.0.1

License

MIT

Last publish

Collaborators

  • pe8ter