GithubHelp home page GithubHelp logo

semabigcorp / node-portfinder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from http-party/node-portfinder

0.0 0.0 0.0 174 KB

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

Home Page: https://github.com/http-party/node-portfinder

License: Other

JavaScript 100.00%

node-portfinder's Introduction

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/Maintainer: Erik Trom

License: MIT/X11

node-portfinder's People

Contributors

eriktrom avatar indexzero avatar winfinit avatar jucrouzet avatar prithvirajbilla avatar masterodin avatar dcharbonnier avatar chyzwar avatar kayakyakr avatar dependabot[bot] avatar jj avatar mmalecki avatar ni-kit avatar xiaofan9 avatar cades avatar msbit avatar tomhughes avatar pimterry avatar inlined avatar nairboon avatar kylev avatar kemitchell avatar rgbkrk avatar kwiatkk1 avatar lostinbrittany avatar kiwiupover avatar dguettler avatar brunogaspar avatar selfcontained avatar basarat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.