portfinder

A simple tool to find an open port on the current machine

MIT 44 个版本
安装
npm install portfinder
yarn add portfinder
pnpm add portfinder
bun add portfinder
README

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

版本列表
1.0.38 2025-09-12
1.0.37 2025-04-28
1.0.36 2025-04-14
1.0.35 2025-03-14
1.0.34 2025-03-11
1.0.33 2025-02-26
1.0.32 2022-08-13
1.0.31 2022-08-13
1.0.30 2022-08-13
1.0.29 2022-08-06
1.0.28 2020-07-29
1.0.27 2020-07-20
1.0.26 2020-04-28
1.0.25 2019-10-15
1.0.24 2019-09-05
1.0.23 2019-08-19
1.0.22 2019-08-17
1.0.21 2019-07-12
1.0.20 2018-11-30
1.0.19 2018-10-23
1.0.18 2018-10-17
1.0.17 2018-08-20
1.0.16 2018-08-07
1.0.15 2018-08-06
1.0.13 2017-01-31
1.0.12 2017-01-17
1.0.11 2017-01-17
1.0.10 2016-11-11
1.0.9 2016-10-18
1.0.8 2016-10-17
1.0.7-beta.0 2016-08-16
1.0.7 2016-08-16
1.0.6 2016-08-07
1.0.5 2016-07-16
1.0.4 2016-07-14
1.0.3 2016-03-23
1.0.2 2016-03-02
1.0.1 2016-02-10
1.0.0 2016-02-03
0.4.0 2015-02-06
0.3.0 2014-12-17
0.2.1 2011-11-20
0.2.0 2011-07-11
0.1.0 2011-07-08