Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function check(port, host) {
var deferred = getDeferred();
var inUse = true;
var client;
var opts;
if (!is.obj(port)) {
opts = makeOptionsObj(port, host);
} else {
opts = port;
}
if (!is.port(opts.port)) {
debug('Error invalid port: '+util.inspect(opts.port));
deferred.reject(new Error('invalid port: '+util.inspect(opts.port)));
return deferred.promise;
}
if (is.nullOrUndefined(opts.host)) {
debug('set host address to default 127.0.0.1');
opts.host = '127.0.0.1';
}
function cleanUp() {
if (client) {
client.removeAllListeners('connect');
client.removeAllListeners('error');
client.end();
client.destroy();