orionsoft-react-scripts
Version:
Orionsoft Configuration and scripts for Create React App.
123 lines (88 loc) • 2.43 kB
Markdown
//img.shields.io/npm/v/detect-port.svg?style=flat-square
[ ]: https://npmjs.org/package/detect-port
[ ]: https://img.shields.io/travis/xudafeng/detect-port.svg?style=flat-square
[ ]: https://travis-ci.org/xudafeng/detect-port
[ ]: https://img.shields.io/coveralls/xudafeng/detect-port.svg?style=flat-square
[ ]: https://coveralls.io/r/xudafeng/detect-port?branch=master
[ ]: https://img.shields.io/badge/node.js-%3E=_0.11.14-red.svg?style=flat-square
[ ]: http://nodejs.org/download/
[ ]: https://img.shields.io/npm/dm/detect-port.svg?style=flat-square
[ ]: https://npmjs.org/package/detect-port
> port detector
```shell
$ npm i detect-port -g
```
```shell
$ detect -p 80
$ detect --port 80
$ port: 80 was occupied, try port: 1024
$ detect --port 80 --verbose
$ detect -h
```
```shell
$ npm i detect-port --save
```
```javascript
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);
}
});
```
```shell
$ git clone git://github.com/xudafeng/detect-port.git
$ cd detect-port
$ make install
$ make test
```
[ ](LICENSE)
Copyright (c) 2015 xdf
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Coveralls][coveralls-image]][coveralls-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]
[ ]: https: