Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/austinkelleher/porti
Node.js utility for system ports
https://github.com/austinkelleher/porti
node port random unused utility
Last synced: 2 months ago
JSON representation
Node.js utility for system ports
- Host: GitHub
- URL: https://github.com/austinkelleher/porti
- Owner: austinkelleher
- License: mit
- Created: 2015-06-18T12:13:39.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-05T21:13:18.000Z (over 7 years ago)
- Last Synced: 2024-10-04T19:43:27.534Z (3 months ago)
- Topics: node, port, random, unused, utility
- Language: JavaScript
- Size: 16.6 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# porti
[![Build Status](https://travis-ci.org/austinkelleher/porti.svg)](https://travis-ci.org/austinkelleher/porti)
![NPM version](https://badge.fury.io/js/porti.svg)Node.js utility for obtaining random TCP ports
## Installation
```bash
npm install porti --save
```## Usage
```javascript
const porti = require('porti');// Finding an unused port in a range of ports. If a range is not specified,
// Porti starts at port 1024 and stops when it has found an unused port.
// None of the properties in the first options argument are required.
porti.getUnusedPort({
min: 2000, // lower bound of random port range to select from
max: 5000, // upper bound of random port range to select from
}).then((port) => {
...
}).catch((err) => {
...
})
```Synchronous API:
```js
// Finding an unused port in a range of ports. If a range is not specified,
// Porti starts at port 1024 and stops when it has found an unused port.
// None of the properties in the first options argument are required.
const port = porti.getUnusedPortSync({
min: 2000, // lower bound of random port range to select from
max: 5000, // upper bound of random port range to select from
})
```