Giter Site home page Giter Site logo

gaearon / detect-port Goto Github PK

View Code? Open in Web Editor NEW

This project forked from node-modules/detect-port

2.0 2.0 1.0 13 KB

JavaScript Implementation of Port Detector

Home Page: https://www.npmjs.com/package/detect-port

License: MIT License

Makefile 10.74% JavaScript 89.26%

detect-port's Introduction

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

detect-port's People

Contributors

antife-yinyue avatar gaearon avatar xudafeng avatar ziczhu avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

rubythonode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.