ItsJohnB ItsJohnB - 1 year ago 152
Node.js Question

Sails.js server bootstrap

I'm currently working with Sails.js and have hopefully a simple question for you. In this small project I work with auctions which end on a specific date.

My question is how can I make a "cron job look a like" which checks every auction end time.

I tried the following code:

var cronJob = require('cron').CronJob;
new cronJob('1 * * * * *', function(){
console.log('You will see this message every second');
}, null, true, null);

The problem is when multiple users go to the page of the auction, multiple cronjobs will execute. Is there a way to make a bootstrap file in Sails.js after the start of the server or something like that?

Answer Source

There sure is:!documentation/config.bootstrap. See bootstrap.js in your config folder.

That said, I'm not sure if using crons is the best way to handle it (resource consuming and inefficient), I would try organizing the code in an event-based manner instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download