Socket
Socket
Sign inDemoInstall

find-free-port

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    find-free-port

find a free tcp port to listen locally


Version published
Weekly downloads
15K
decreased by-13.78%
Maintainers
1
Install size
5.96 kB
Created
Weekly downloads
 

Readme

Source

find-free-port

Find free tcp port or pors to listen on. The definition of 'free' port is that connecting to this port and host ('localhost' by default) will not succeed, and thus 'free'.

Installation

npm install find-free-port --save

Examples

Find a free port to listen on that is >= 3000

var fp = require("find-free-port")
fp(3000, function(err, freePort){
});

Find a free port to listen on that is >= 3000 and < 3100

var fp = require("find-free-port")
fp(3000, 3100, function(err, freePort){
});

Find 3 free ports to listen on that is >= 3000 locally

var fp = require("find-free-port")
fp(3000, 3100, '127.0.0.1', 3, function(err, p1, p2, p3){
});

Find a free port that is >= 3000 and at host 192.168.100.1

var fp = require("find-free-port")
fp(3000, "192.168.100.1", function(err, freePort){
});

Promise

If the callback is omitted, then the call returns a Promise that resolve to a list of avaiable ports:

var fp = require("find-free-port")
fp(3000).then(([freep]) => {
    console.log('found ' + freep);
}).catch((err)=>{
    console.error(err);
});

Keywords

FAQs

Last updated on 25 Jun 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc