New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

detect-port

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-port - npm Package Compare versions

Comparing version

to
0.1.4

5

HISTORY.md

@@ -0,1 +1,6 @@

0.1.4 / 2015-08-24
===================
* Support promise
0.1.2 / 2014-05-31

@@ -2,0 +7,0 @@ ===================

84

lib/index.js

@@ -29,53 +29,55 @@ /* ================================================================

var _detect = function(_fn) {
var socket = new net.Socket();
socket.once('error', function() {
socket.removeAllListeners('connect');
socket.removeAllListeners('error');
socket.end();
socket.destroy();
socket.unref();
var server = new net.Server();
server.on('error', function() {
var _detect = function(port) {
return new Promise(function(resolve, reject) {
var socket = new net.Socket();
socket.once('error', function() {
socket.removeAllListeners('connect');
socket.removeAllListeners('error');
socket.end();
socket.destroy();
socket.unref();
var server = new net.Server();
server.on('error', function() {
inject(port);
port++;
resolve(_detect(port));
});
server.listen(port, function() {
server.once('close', function() {
resolve(port);
});
server.close();
});
});
socket.once('connect', function() {
inject(port);
port++;
if (fn) {
_detect(_fn);
} else {
detect(port)(_fn);
}
resolve(_detect(port));
socket.removeAllListeners('connect');
socket.removeAllListeners('error');
socket.end();
socket.destroy();
socket.unref();
});
server.listen(port, function() {
server.once('close', function() {
_fn(null, port);
});
server.close();
socket.connect({
port: port,
host: ipv4
});
});
socket.once('connect', function() {
inject(port);
port++;
}
if (fn) {
_detect(_fn);
} else {
detect(port)(_fn);
}
socket.removeAllListeners('connect');
socket.removeAllListeners('error');
socket.end();
socket.destroy();
socket.unref();
});
socket.connect({
port: port,
host: ipv4
});
var _detect_with_cb = function(_fn) {
_detect(port)
.then(function(result) {
_fn(null, result);
})
.catch(function(e) {
_fn(e);
});
};
return fn ? _detect(fn) : _detect;
return fn ? _detect_with_cb(fn) : _detect(port);
}
module.exports = detect;
{
"name": "detect-port",
"version": "0.1.3",
"version": "0.1.4",
"description": "port detector",

@@ -38,3 +38,3 @@ "keywords": [

"engines": {
"node": ">= 11.14.x"
"node": ">= 0.11.14"
},

@@ -41,0 +41,0 @@ "author": "xudafeng",

@@ -83,2 +83,16 @@ detect-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);
}
});
```

@@ -85,0 +99,0 @@