Irina Glushko 2389e7160b HW1 done vor 3 Jahren
..
.vscode 2389e7160b HW1 done vor 3 Jahren
bin 2389e7160b HW1 done vor 3 Jahren
lib 2389e7160b HW1 done vor 3 Jahren
node_modules 2389e7160b HW1 done vor 3 Jahren
.eslintignore 2389e7160b HW1 done vor 3 Jahren
.eslintrc 2389e7160b HW1 done vor 3 Jahren
CONTRIBUTING.md 2389e7160b HW1 done vor 3 Jahren
HISTORY.md 2389e7160b HW1 done vor 3 Jahren
LICENSE 2389e7160b HW1 done vor 3 Jahren
README.md 2389e7160b HW1 done vor 3 Jahren
appveyor.yml 2389e7160b HW1 done vor 3 Jahren
index.js 2389e7160b HW1 done vor 3 Jahren
logo.png 2389e7160b HW1 done vor 3 Jahren
package.json 2389e7160b HW1 done vor 3 Jahren

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