Skip to content

danielstjules/openports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openports

Find multiple open ports.

Build Status

Installation

npm install --save openports

Usage

/**
 * Returns n open ports. Uses port 0 for port discovery, and binds to all ports
 * prior to releasing them to help avoid race conditions. Accepts an optional
 * callback, otherwise it returns a promise.
 *
 * @param   {int}      n    Number of ports to open
 * @param   {function} [fn] Optional callback to invoke
 * @returns {Promise}  An array of port numbers
 */

Example

var openports = require('openports');

openports(1, function(err, ports) {
  console.log(ports); // [12345]
});

openports(2).then(function(ports) {
  console.log(ports); // [12345, 12346]
});