detect-port
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,3 +0,3 @@ | ||
Contributing to macaca | ||
====================== | ||
Contributing to detect-port | ||
=========================== | ||
@@ -4,0 +4,0 @@ - Fork the project, make a change, and send a pull request; |
@@ -18,7 +18,16 @@ /* ================================================================ | ||
var localhost = '0.0.0.0'; | ||
var options = global.__detect ? global.__detect.options : {}; | ||
var inject = function(port) { | ||
var options = global.__detect ? global.__detect.options : {}; | ||
if (options.verbose) { | ||
console.log('port %d was occupied', port); | ||
} | ||
}; | ||
function detect(port, fn) { | ||
var _detect = function(_fn) { | ||
var server = http.createServer(); | ||
server.listen(port, localhost, function() { | ||
@@ -35,7 +44,5 @@ server.once('close', function() { | ||
}); | ||
server.on('error', function() { | ||
if (options.verbose) { | ||
console.log('Port %d was occupied', port); | ||
} | ||
inject(port); | ||
port++; | ||
@@ -42,0 +49,0 @@ |
{ | ||
"name": "detect-port", | ||
"version": "0.1.0", | ||
"description": "detect free port", | ||
"version": "0.1.1", | ||
"description": "port detector", | ||
"keywords": ["detect", "port", "detect-port"], | ||
@@ -16,4 +16,3 @@ "bin": { | ||
"dependencies": { | ||
"co": "3", | ||
"commander": "~2.0.0" | ||
"commander": "~2.8.1" | ||
}, | ||
@@ -24,3 +23,3 @@ "devDependencies": { | ||
"istanbul": "*", | ||
"should": "~4.0.4", | ||
"should": "~6.0.3", | ||
"jshint": "*" | ||
@@ -36,3 +35,3 @@ }, | ||
"engines": { | ||
"node": ">= 10.0.x" | ||
"node": ">= 11.14.x" | ||
}, | ||
@@ -39,0 +38,0 @@ "author": "xudafeng", |
detect-port | ||
=========== | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![node version][node-image]][node-url] | ||
[![npm download][download-image]][download-url] | ||
[npm-image]: https://img.shields.io/npm/v/detect-port.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/detect-port | ||
[travis-image]: https://img.shields.io/travis/xudafeng/detect-port.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/xudafeng/detect-port | ||
[coveralls-image]: https://img.shields.io/coveralls/xudafeng/detect-port.svg?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/xudafeng/detect-port?branch=master | ||
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.11.14-green.svg?style=flat-square | ||
[node-url]: http://nodejs.org/download/ | ||
[download-image]: https://img.shields.io/npm/dm/detect-port.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/detect-port | ||
> port detector | ||
@@ -8,3 +25,3 @@ | ||
```bash | ||
```shell | ||
$ npm i detect-port -g | ||
@@ -15,6 +32,72 @@ ``` | ||
```bash | ||
```shell | ||
# 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 | ||
```js | ||
var detect = require('detect-port'); | ||
/** | ||
* normal usage | ||
*/ | ||
detect(port, 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); | ||
} | ||
}); | ||
/** | ||
* 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); | ||
} | ||
})(); | ||
``` | ||
## Clone and Run test | ||
```shell | ||
# 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 | ||
@@ -24,2 +107,2 @@ | ||
Copyright (c) 2014 xdf | ||
Copyright (c) 2015 xdf |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 12 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
340207
1
36
61
106
26
+ Addedcommander@2.8.1(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
- Removedco@3
- Removedco@3.1.0(transitive)
- Removedcommander@2.0.0(transitive)
Updatedcommander@~2.8.1