@timer/detect-port
detect available port
Last updated 7 years ago by gaearon .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @timer/detect-port 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.3                                ...           latest (7 years ago)

2 Versions

  • 1.1.3                                ...           7 years ago
  • 1.1.2                                ...           8 years ago
Maintainers (2)
Downloads
Total 2
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (6)

© 2010 - cnpmjs.org x YWFE | Home | YWFE