ko-port

1.2.1 • Public • Published

ko-port

make sure get an available port on your server

支持本地安装(Local Installation)

$ npm install ko-port

支持全局安装(Global Installation)

$ npm install ko-port -g

支持API

  • asyncPort(port: number): Promise<any>

识别指定port是否可用,否则递归加1,返回有效port

样例:

var koport = require('ko-port');
 
koport.asyncPort(3000)
  .then((port) => {
      // 返回有效port
      http.createServer(app).listen(port, function () {
          console.log('listening on port ', port)
      })
  })
  .catch((err) => {
      // 返回err
  });
  • killPort(port: number): Promise<any>

杀死指定的port占用进程

样例:

var koport = require('ko-port');
 
koport.killPort(3000)
  .then(() => {
      // success
  })
  .catch((err) => {
      // error
  });

如果是全局(Global)安装:

$ koport 3000

Readme

Keywords

Package Sidebar

Install

npm i ko-port

Weekly Downloads

9

Version

1.2.1

License

ISC

Unpacked Size

3.62 kB

Total Files

4

Last publish

Collaborators

  • kicoyu