katoikia-app/web-ui/web-react/node_modules/detect-port-alt
Maria Sanchez 5abf040b42 fix web ui template 2022-07-05 22:15:11 -06:00
..
.vscode fix web ui template 2022-07-05 22:15:11 -06:00
bin fix web ui template 2022-07-05 22:15:11 -06:00
lib fix web ui template 2022-07-05 22:15:11 -06:00
node_modules/debug fix web ui template 2022-07-05 22:15:11 -06:00
.eslintignore fix web ui template 2022-07-05 22:15:11 -06:00
.eslintrc fix web ui template 2022-07-05 22:15:11 -06:00
CONTRIBUTING.md fix web ui template 2022-07-05 22:15:11 -06:00
HISTORY.md fix web ui template 2022-07-05 22:15:11 -06:00
LICENSE fix web ui template 2022-07-05 22:15:11 -06:00
README.md fix web ui template 2022-07-05 22:15:11 -06:00
appveyor.yml fix web ui template 2022-07-05 22:15:11 -06:00
index.js fix web ui template 2022-07-05 22:15:11 -06:00
logo.png fix web ui template 2022-07-05 22:15:11 -06:00
package.json fix web ui template 2022-07-05 22:15:11 -06:00

README.md

logo


NPM version build status Test coverage npm download

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

MIT