express - Is there a way to start a task before node.js server.listen event is emitted? -
i want able start async task before server starts listen port , gets requests, workaround invoke task onlistening function , when task done i'm binding port address - workaround ugly..
function onlistening() { var addr = server.address(); var bind; // following service gets default plugins yamls , stores them in db. defaultoperationsservice.getootboperations().then(function success() { logger.info('done getting default plugins operations!'); }, function err(err) { logger.error('error while trying operations' + err); }).done(function done() { bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; logger.debug('listening on ' + bind); }); }
i introduced better way , best way, call server.listen(port) when done:
defaultoperationsservice.getootboperations().then(function success(){ logger.info('done getting default plugins operations!'); }, function err(err){ logger.error('error while trying operations' + err); }).done(function done(){ server.listen(port); });
Comments
Post a Comment