This repository has been archived on 2026-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
todo/client/node_modules/detect-port-alt
2025-06-13 14:04:40 +08:00
..
.vscode Initial commit 2025-06-13 14:04:40 +08:00
bin Initial commit 2025-06-13 14:04:40 +08:00
lib Initial commit 2025-06-13 14:04:40 +08:00
node_modules Initial commit 2025-06-13 14:04:40 +08:00
.eslintignore Initial commit 2025-06-13 14:04:40 +08:00
.eslintrc Initial commit 2025-06-13 14:04:40 +08:00
appveyor.yml Initial commit 2025-06-13 14:04:40 +08:00
CONTRIBUTING.md Initial commit 2025-06-13 14:04:40 +08:00
HISTORY.md Initial commit 2025-06-13 14:04:40 +08:00
index.js Initial commit 2025-06-13 14:04:40 +08:00
LICENSE Initial commit 2025-06-13 14:04:40 +08:00
logo.png Initial commit 2025-06-13 14:04:40 +08:00
package.json Initial commit 2025-06-13 14:04:40 +08:00
README.md Initial commit 2025-06-13 14:04:40 +08: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