Skip to content

returns a promise to find the first open port within a range on `localhost`

License

Notifications You must be signed in to change notification settings

codekirei/first-open-port

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

first-open-port

Build Status Coverage Status


About | Installation | Usage | License

About

A tiny Node.js module to get the first available port on localhost in a given range. Handy for avoiding hard-coded port conflicts (EADDRINUSE) if you frequently spin up more than one local server during development. Returns a Promise.

Installation

Install and require as a standard Node module.

Install

  $ npm install --save first-open-port

Require

  var firstOpenPort = require('first-open-port')

Usage

firstOpenPort(start, max)

  • start : Number : begin search at this port
  • (max) : Number : optional last port to search before rejecting

Returns a bluebird Promise that resolves with the first open port or rejects with an error if no open ports are found in the given range.

var firstOpenPort = require('first-open-port')

firstOpenPort(3000, 3100)
  .then(port => {
    // start a server on that port
  })
  .catch(err => {
    // do something when no ports are available
  })

License

MIT

About

returns a promise to find the first open port within a range on `localhost`

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published