portfinder
A simple tool to find an open port on the current machine
Last updated 4 months 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.20                                ...           latest (4 months ago)

26 Versions

  • 1.0.20                                ...           4 months ago
  • 1.0.19                                ...           5 months ago
  • 1.0.18                                ...           5 months ago
  • 1.0.17                                ...           7 months ago
  • 1.0.16                                ...           8 months ago
  • 1.0.15                                ...           8 months ago
  • 1.0.13                                ...           2 years ago
  • 1.0.12                                ...           2 years ago
  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 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                                ...           4 years ago
  • 0.2.1                                ...           7 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (2)
Downloads
Today 730
This Week 730
This Month 365,860
Last Day 8,150
Last Week 113,829
Last Month 300,620
Dependencies (3)
Dev Dependencies (2)
Dependents (813)

Copyright 2014 - 2016 © taobao.org |