findandbind

Find and bind to free port in restify/express/connect.

Find and bind

Find a free port to which to bind.

 
var app = restify.createServer();
 
// ... do my configuration of app 
 
require('findandbind')(app, function (errport) {
    console.log('listening on', port);
});

By default, findandbind starts checking at 1024, the first user port. To start checking at a different port:

 
require('findandbind')(app, { start: 2048 }, function (errport) {
    console.log('listening on', port);
});