Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Will use any port from 3000 to 3100, otherwise fall back to a random port
})();
```
## API
### getPort([options])
Returns a `Promise` for a port number.
#### options
Type: `Object`
##### port
Type: `number | Iterable<number>`
A preferred port or an iterable of preferred ports to use.
##### host
Type: `string`
The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.
### getPort.makeRange(from, to)
Make a range of ports `from`...`to`.
Returns an `Iterable` for ports in the given range.
#### from
Type: `number`
First port of the range. Must be in the range `1024`...`65535`.
#### to
Type: `number`
Last port of the range. Must be in the range `1024`...`65535` and must be greater than `from`.
## Beware
There is a very tiny chance of a race condition if another service starts using the same port number as you in between the time you get the port number and you actually start using it.
## Related
-[get-port-cli](https://github.com/sindresorhus/get-port-cli) - CLI for this module
**2019-03-12** - 5th birthday of systeminformation. This is amazing. Started as a small projekt just for myself, it now has > 8,000 lines of code, > 200 versions published, up to 100,000 downloads per month, > 1 Mio downloads overall. Thank you to all who contributed to this project!
This is amazing. Started as a small project just for myself, it now has > 9,000 lines of code, > 250 versions published, up to 400,000 downloads per month, > 1 Mio downloads overall. Thank you to all who contributed to this project!