lib/port-finder.js
function checkPort(port, cb) {
  var server = new net.Server();
  server.on('error', function (err) {
    server.removeAllListeners();
    cb(err);
  });
  server.listen(port, function () {
    server.on('close', function () {
      server.removeAllListeners();
      cb(null, port);
    });
    server.close();
  });
}
function checkPort(port, cb) {
  var server = new net.Server();
  server.on('error', function (err) {
    server.removeAllListeners();
    cb(err);
  });
  server.listen(port, function () {
    server.on('close', function () {
      server.removeAllListeners();
      cb(null, port);
    });
    server.close();
  });
}
function checkPort ( port , cb ) { var server = new net . Server ( ) ; server . on ( 'error' , function ( err ) { server . removeAllListeners ( ) ; cb ( err ) ; } ) ; server . listen ( port , function ( ) { server . on ( 'close' , function ( ) { server . removeAllListeners ( ) ; cb ( null , port ) ; } ) ; server . close ( ) ; } ) ; }
Check if a port is available

@param {Number} port The port to check if available
@param {Function} cb Function called as result
@param {Error} cb.err The error if occurred
@param {Number} cb.port The port if available
@private
@ignore
Check if a port is available