getport

Find an open port to listen on.

npm install getport

Find an open port to listen on.

var getport = require('getport')
getport(function (ep) {
  if (e) throw e
  server.listen(p)
})

Note: getport uses a TCP client to check the ports and see if anyone has bound to them. If you do not have permission to bind to a port you may still get an error.

getport(5000, function (ep) {
  if (e) throw e
  assert.equal(5000, p)
})
getport(6000, 5999, function (ep) {
  assert.ok(e)
})