My script performs some asynchronous tasks using promises (with the q library). Running mocha tests works fine. However running the script from the command line does not. The node process immediately dies.
var bot = require('./bot');
bot.getCategories().then(function (categories) {
console.log('Found ' + categories.length + ' categories');
});
My script performs some asynchronous tasks using promises (with the q library). Running mocha tests works fine. However running the script from the command line does not. The node process immediately dies.
This is most certainly a bug, please do report it. The Node.js environment should not exit prematurely while there are things still queued in the event loop.
You should not have to alter your code one bit for this to happen. The Q library (keep in mind there are more modern and native alternatives today) schedules async callbacks on the process.nextTick
"microtask" queue. Your bot library presumably also performs IO, both these things should cause node not to terminate.
Node.js will exit when there are no more callbacks to process. You can use setInterval or setTimeout to always keep one so that the process does not automatically exit.
function wait () {
if (!EXITCONDITION)
setTimeout(wait, 1000);
};
wait();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With