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);

最新文章

  1. 【菜鸟学习jquery源码】数据缓存与data()
  2. win10 MySQL启动失败问题
  3. MD5加密算法实现用户信息加密
  4. LeetCode Flip Game
  5. Socket状态变迁图
  6. 创建immutable类
  7. Android MVPR 架构模式
  8. 解决IE6下png图片不透明
  9. ImageMagick的使用
  10. hdu 1232畅通工程
  11. protobuf 参考资料
  12. 破解.net程序 编译和反编译方法
  13. hdu2089(数位dp)
  14. PDF解决方案(3)--PDF转SWF
  15. elasticsearch文档-analysis
  16. LeetCode - 728. Self Dividing Numbers
  17. 【一天一道LeetCode】#64. Minimum Path Sum.md
  18. asp.net core session丢失问题排查
  19. 启用k8s metrics server监控
  20. MVC5 Entity Framework学习

热门文章

  1. Linux下查看文件内容的命令和工具
  2. linux 上安装多个不同版本的mysql 踩的坑
  3. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.thinkplatform.dao.UserLogDao' available: expected at least 1 bean which qualifies as autowi
  4. 没错,老板让我写个 BUG!
  5. springboot~mybatis里localdatetime序列化问题
  6. C# net request payload形式发送post请求
  7. Python两步实现关联规则Apriori算法,参考机器学习实战,包括频繁项集的构建以及关联规则的挖掘
  8. python实现某目录下将多个文件夹内的文件复制到一个文件夹中
  9. PLSQL 登录出现 ora12638 credential retrieval failed
  10. win10安装tensorflow-gpu1.13.1+cuda10.0+cudnn7.3.1