Frontend/25_01_07/mai/node_modules/detect-port-alt
szabomarton 7f4a15b9c3 asd
2025-01-28 11:38:27 +01:00
..
.vscode asd 2025-01-28 11:38:27 +01:00
bin asd 2025-01-28 11:38:27 +01:00
lib asd 2025-01-28 11:38:27 +01:00
node_modules asd 2025-01-28 11:38:27 +01:00
.eslintignore asd 2025-01-28 11:38:27 +01:00
.eslintrc asd 2025-01-28 11:38:27 +01:00
appveyor.yml asd 2025-01-28 11:38:27 +01:00
CONTRIBUTING.md asd 2025-01-28 11:38:27 +01:00
HISTORY.md asd 2025-01-28 11:38:27 +01:00
index.js asd 2025-01-28 11:38:27 +01:00
LICENSE asd 2025-01-28 11:38:27 +01:00
logo.png asd 2025-01-28 11:38:27 +01:00
package.json asd 2025-01-28 11:38:27 +01:00
README.md asd 2025-01-28 11:38:27 +01: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