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

node-portfinder

CI

Installation

You can install portfinder using a package manager like npm, yarn, or bun:

npm install portfinder

Usage

The portfinder module has a simple interface:

const portfinder = require('portfinder');

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

Or using promises:

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.
    //
  });

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.38                                ...           latest (7 months ago)

44 Versions

  • 1.0.38                                ...           7 months ago
  • 1.0.37                                ...           a year ago
  • 1.0.36                                ...           a year ago
  • 1.0.35                                ...           a year ago
  • 1.0.34                                ...           a year ago
  • 1.0.33                                ...           a year ago
  • 1.0.32                                ...           4 years ago
  • 1.0.31                                ...           4 years ago
  • 1.0.30                                ...           4 years ago
  • 1.0.29                                ...           4 years ago
  • 1.0.28                                ...           6 years ago
  • 1.0.27                                ...           6 years ago
  • 1.0.26                                ...           6 years ago
  • 1.0.25                                ...           6 years ago
  • 1.0.24                                ...           7 years ago
  • 1.0.23                                ...           7 years ago
  • 1.0.22                                ...           7 years ago
  • 1.0.21                                ...           7 years ago
  • 1.0.20                                ...           7 years ago
  • 1.0.19                                ...           7 years ago
  • 1.0.18                                ...           7 years ago
  • 1.0.17                                ...           8 years ago
  • 1.0.16                                ...           8 years ago
  • 1.0.15                                ...           8 years ago
  • 1.0.13                                ...           9 years ago
  • 1.0.12                                ...           9 years ago
  • 1.0.11                                ...           9 years ago
  • 1.0.10                                ...           9 years ago
  • 1.0.9                                ...           9 years ago
  • 1.0.8                                ...           9 years ago
  • 1.0.7                                ...           10 years ago
  • 1.0.7-beta.0                                ...           10 years ago
  • 1.0.6                                ...           10 years ago
  • 1.0.5                                ...           10 years ago
  • 1.0.4                                ...           10 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.4.0                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.2.1                                ...           14 years ago
  • 0.2.0                                ...           15 years ago
  • 0.1.0                                ...           15 years ago

Copyright 2013 - present © cnpmjs.org | Home |