Darius Moseley
Darius Moseley

Reputation: 57

NodeJS - How to run functions everytime end/start of day is reached?

I am trying to implement daily user stats into my app and I'd like to reset these stats at the end/beginning of each day. How could I do this in NodeJS?

Upvotes: 0

Views: 324

Answers (1)

Damian Krawczyk
Damian Krawczyk

Reputation: 2241

You can use node-cron. This will allow you to run a function in exact time. As example:

var CronJob = require('cron').CronJob;
new CronJob('00 00 00 * * *', () => {
  console.log('This will execute on midnight');
}, null, true);

Upvotes: 1

Related Questions