mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-12-24 23:59:00 +00:00
.. | ||
.vscode | ||
bin | ||
lib | ||
node_modules | ||
.eslintignore | ||
.eslintrc | ||
appveyor.yml | ||
CONTRIBUTING.md | ||
HISTORY.md | ||
index.js | ||
LICENSE | ||
logo.png | ||
package.json | ||
README.md |
JavaScript Implementation of Port Detector
Usage
$ npm i detect-port --save
const detect = require('detect-port');
/**
* callback usage
*/
detect(port, (err, _port) => {
if (err) {
console.log(err);
}
if (port == _port) {
console.log(`port: ${port} was not occupied`);
} else {
console.log(`port: ${port} was occupied, try port: ${_port}`);
}
});
/**
* for a yield syntax instead of callback function implement
*/
const co = require('co');
co(function *() {
const _port = yield detect(port);
if (port == _port) {
console.log(`port: ${port} was not occupied`);
} else {
console.log(`port: ${port} was occupied, try port: ${_port}`);
}
});
/**
* use as a promise
*/
detect(port)
.then(_port => {
if (port == _port) {
console.log(`port: ${port} was not occupied`);
} else {
console.log(`port: ${port} was occupied, try port: ${_port}`);
}
})
.catch(err => {
console.log(err);
});
Command Line Tool
$ npm i detect-port -g
Quick Start
# get an available port randomly
$ detect
# detect pointed port
$ detect 80
# more help
$ detect --help