GoScrobble/web/node_modules/detect-port-alt
2022-04-25 14:48:54 +12:00
..
.vscode 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
bin 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
lib 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
node_modules 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
.eslintignore 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
.eslintrc 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
appveyor.yml 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
CONTRIBUTING.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
HISTORY.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
LICENSE 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
logo.png 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
package.json 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
README.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00

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