首页 > 其他 > 详细

node-portfinder

时间:2019-04-25 19:18:39      阅读:349      评论:0      收藏:0      [点我收藏+]

nstallation

  $ [sudo] npm install portfinder
 

Usage

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

Promise形式

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.basePort = 3000;    // default: 8000
portfinder.highestPort = 3333; // default: 65535

默认端口从8000扫描到65535,上面两个方法可以i实现自定义扫描范围

or by passing optional options object on each invocation:

portfinder.getPort({
    port: 3000,    // minimum port
    stopPort: 3333 // maximum port
}, callback);

 

node-portfinder

原文:https://www.cnblogs.com/cangqinglang/p/10770297.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!