detect-port-alt (1.1.6)
Published 2026-02-24 13:55:28 +00:00 by atheaadmin
Installation
registry=npm install detect-port-alt@1.1.6"detect-port-alt": "1.1.6"About this package
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
Authors
License
Dependencies
Dependencies
| ID | Version |
|---|---|
| address | ^1.0.1 |
| debug | ^2.6.0 |
Development Dependencies
| ID | Version |
|---|---|
| command-line-test | ^1.0.8 |
| egg-bin | ^1.10.3 |
| egg-ci | ^1.1.0 |
| eslint | ^3.13.1 |
| eslint-config-egg | ^3.1.0 |
| pedding | ^1.1.0 |
Keywords
detect
port
