JSPM

  • Created
  • Published
  • Downloads 6177154
  • Score
    100M100P100Q204217F
  • License MIT

port detector

Package Exports

  • detect-port

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (detect-port) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

detect-port

NPM version build status Coveralls David deps node version

port detector

Installment

$ npm i detect-port -g

Quick Start

# detect port 80
$ detect -p 80

# or like this
$ detect --port 80

# will get result below
$ port: 80 was occupied, try port: 1024

# with verbose
$ detect --port 80 --verbose

# more help?
$ detect -h

Use As Module

var detect = require('detect-port');

/**
 * normal usage
 */

detect(port, function(error, _port) {

  if (port === _port) {
    console.log('port: %d was not occupied', port);
  } else {
    console.log('port: %d was occupied, try port: %d', port, _port);
  }
});

/**
 * use in co v3
 * for a yield syntax instead of callback function implement
 */

var co = require('co');

co(function *() {
  var _port = yield detect(port);

  if (port === _port) {
    console.log('port: %d was not occupied', port);
  } else {
    console.log('port: %d was occupied, try port: %d', port, _port);
  }
})();

/**
 * use as a promise
 */

var promisePort = detect(port);

promisePort.then(function(_port) {
  if (port === _port) {
    console.log('port: %d was not occupied', port);
  } else {
    console.log('port: %d was occupied, try port: %d', port, _port);
  }
});

Clone and Run test

# clone from git
$ git clone git://github.com/xudafeng/detect-port.git

$ cd detect-port

# install dependencies
$ make install

# test and coverage
$ make test

License

MIT

Copyright (c) 2015 xdf