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

node-portfinder Build Status

Installation

  $ [sudo] 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 Promise 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.basePort = 3000;    // default: 8000
portfinder.highestPort = 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

Maintainer: Erik Trom

License: MIT/X11

Current Tags

  • 1.0.21                                ...           latest (11 days ago)

27 Versions

  • 1.0.21                                ...           11 days ago
  • 1.0.20                                ...           8 months ago
  • 1.0.19                                ...           9 months ago
  • 1.0.18                                ...           9 months ago
  • 1.0.17                                ...           a year ago
  • 1.0.16                                ...           a year ago
  • 1.0.15                                ...           a year ago
  • 1.0.13                                ...           2 years ago
  • 1.0.12                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.7-beta.0                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.4.0                                ...           4 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (2)
Downloads
Today 611
This Week 52,339
This Month 424,013
Last Day 25,660
Last Week 158,215
Last Month 374,736
Dependencies (3)
Dev Dependencies (2)
Dependents (925)

Copyright 2014 - 2016 © taobao.org |