Package Exports
- find-free-port
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (find-free-port) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
find-free-port
Find free tcp port or ports to listen locally. The definition of 'free' port is that calling nodejs api server.listen(port, ip) results in a 'listening' event instead of 'error' event'.
This implies that it's legal to listen on both '0.0.0.0:12345' and '127.0.0.1:12345', and thus allowed by find-free-port.
Installation
npm install find-free-port --saveExamples
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 a free port to listen on that is >= 3000 and < 3100 and bound to ip 127.0.0.1
var fp = require("find-free-port")
fp(3000, 3100, '127.0.0.1', function(err, freePort){
});Find a free port to listen on that is >= 3000 and bound to ip 127.0.0.1
var fp = require('find-free-port')
fp(3000, '127.0.0.1', function(err, freePort){
});Find 3 free ports to listen on that is >= 3000 and bound to ip 127.0.0.1
var fp = require("find-free-port")
fp(3000, 3100, '127.0.0.1', 3, function(err, p1, p2, p3){
});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);
});