index.js
function isPortTaken(port, fn) {
  const net = require('net')
  const tester = net.createServer()
    .once('error', function (err) {
      if (err.code != 'EADDRINUSE') return fn(err)
      fn(null, true)
    })
    .once('listening', function() {
      tester.once('close', function() { fn(null, false) })
        .close()
    })
    .listen(port)
}
function isPortTaken(port, fn) {
  const net = require('net')
  const tester = net.createServer()
    .once('error', function (err) {
      if (err.code != 'EADDRINUSE') return fn(err)
      fn(null, true)
    })
    .once('listening', function() {
      tester.once('close', function() { fn(null, false) })
        .close()
    })
    .listen(port)
}
function isPortTaken ( port , fn ) { const net = require ( 'net' ) const tester = net . createServer ( ) . once ( 'error' , function ( err ) { if ( err . code != 'EADDRINUSE' ) return fn ( err ) fn ( null , true ) } ) . once ( 'listening' , function ( ) { tester . once ( 'close' , function ( ) { fn ( null , false ) } ) . close ( ) } ) . listen ( port ) }
Checks if a port is already taken by another app.

Source: https://gist.github.com/timoxley/1689041
@param port
@param fn
Checks if a port is already taken by another app .