portfinder
A simple tool to find an open port on the current machine
Last updated 6 years ago by eriktrom .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install portfinder 
SYNC missed versions from official npm registry.

node-portfinder CI

Installation

  $ npm install portfinder

Usage

The portfinder module has a simple interface:

  var portfinder = require('portfinder');

  portfinder.getPort(function (err, port) {
    //
    // `port` is guaranteed to be a free port
    // in this scope.
    //
  });

Or with promise (if Promises are supported) :

  const portfinder = require('portfinder');

  portfinder.getPortPromise()
    .then((port) => {
        //
        // `port` is guaranteed to be a free port
        // in this scope.
        //
    })
    .catch((err) => {
        //
        // Could not get a free port, `err` contains the reason.
        //
    });

If portfinder.getPortPromise() is called on a Node version without Promise (<4), it will throw an Error unless Bluebird or any Promise pollyfill is used.

Ports search scope

By default portfinder will start searching from 8000 and scan until maximum port number (65535) is reached.

You can change this globally by setting:

portfinder.setBasePort(3000);    // default: 8000
portfinder.setHighestPort(3333); // default: 65535

or by passing optional options object on each invocation:

portfinder.getPort({
    port: 3000,    // minimum port
    stopPort: 3333 // maximum port
}, callback);

Run Tests

  $ npm test

Author: Charlie Robbins

Author/Maintainer: Erik Trom

License: MIT/X11

Current Tags

  • 1.0.32                                ...           latest (2 years ago)

38 Versions

  • 1.0.32                                ...           2 years ago
  • 1.0.31                                ...           2 years ago
  • 1.0.30                                ...           2 years ago
  • 1.0.29                                ...           2 years ago
  • 1.0.28                                ...           4 years ago
  • 1.0.27                                ...           4 years ago
  • 1.0.26                                ...           5 years ago
  • 1.0.25                                ...           5 years ago
  • 1.0.24                                ...           5 years ago
  • 1.0.23                                ...           5 years ago
  • 1.0.22                                ...           5 years ago
  • 1.0.21                                ...           5 years ago
  • 1.0.20                                ...           6 years ago
  • 1.0.19                                ...           6 years ago
  • 1.0.18                                ...           6 years ago
  • 1.0.17                                ...           6 years ago
  • 1.0.16                                ...           6 years ago
  • 1.0.15                                ...           6 years ago
  • 1.0.13                                ...           8 years ago
  • 1.0.12                                ...           8 years ago
  • 1.0.11                                ...           8 years ago
  • 1.0.10                                ...           8 years ago
  • 1.0.9                                ...           8 years ago
  • 1.0.8                                ...           8 years ago
  • 1.0.7                                ...           8 years ago
  • 1.0.7-beta.0                                ...           8 years ago
  • 1.0.6                                ...           8 years ago
  • 1.0.5                                ...           8 years ago
  • 1.0.4                                ...           8 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.4.0                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.1                                ...           13 years ago
  • 0.2.0                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
Maintainers (2)
Downloads
Total 5
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE