fuckport
v2.0.2
Published
处理关于端口的诸多相关!
Downloads
24
Readme
fuckport
Kill ports
Get an available port
Get ports's PIDS Cross platform
Rationale
List port info :
$
lsof -i :<port>
for Unix
$netstat -ano|findstr "<port>"
for WindowsKill pid :
$
kill -9 <pid>
for Unix
$taskkill /F /pid "<pid>"
for Windows
Installation
$ npm i --save fuckport
Usage
const fuckport = require('fuckport')
//获取一个随机可用的端口
funckport.getPort().then(port => console.log(port))
//=>eg: 3000
//获取一个可用端口,优先返回传入的端口(如果已被占用则返回一个随机可用端口)
funckport.getPort(8080).then(port => console.log(port))
//=>eg: 8080 or 3000 ...
//获取一个可用端口,返回传入的端口(如果占用中则kill掉)
funckport.getPort(8080, true).then(port => console.log(port))
//=>eg: 8080
//获取一组端口的对应pid信息,返回pid数组(未被占用返回-1)
funckport.getPortsPids([8080, 8089, 3000]]).then(pids => console.log(pids))
//=>eg: [43533, -1, 34556]
//解除一组端口的占用 返回pid数组
funckport.killPorts([8080, 8089, 3000]]).then(pids => console.log(pids))
//=>eg: [ -1, -1, 536 ]
Test
$ npm test
Commit
$ npm run commit 'a test commit msg' && git push
License
LGPL