You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mahdi
0cb8d673d7
|
2 years ago | |
---|---|---|
.. | ||
.vscode | 2 years ago | |
bin | 2 years ago | |
lib | 2 years ago | |
node_modules | 2 years ago | |
.eslintignore | 2 years ago | |
.eslintrc | 2 years ago | |
CONTRIBUTING.md | 2 years ago | |
HISTORY.md | 2 years ago | |
LICENSE | 2 years ago | |
README.md | 2 years ago | |
appveyor.yml | 2 years ago | |
index.js | 2 years ago | |
logo.png | 2 years ago | |
package.json | 2 years ago |
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