Reputation: 5858
In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time).
Say if the date and time is [email protected] we need to run the email code at that time.
I think this package will full fill our needs https://www.npmjs.com/package/node-schedule,
Here is their documentation
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
But it doesn't say how to run on specific date (year field is missing??) so how do i achieve my need?
Upvotes: 2
Views: 14744
Reputation: 5835
You can pass date object in it. if you read document further you will find it here : https://www.npmjs.com/package/node-schedule#date-based-scheduling
var schedule = require('node-schedule');
var date = new Date(2012, 11, 21, 5, 30, 0);
var j = schedule.scheduleJob(date, function(){
console.log('The world is going to end today.');
});
Upvotes: 1
Reputation: 100205
for specific date, you could use something like following as provided in example
var schedule = require('node-schedule');
var date = new Date(2018, 1, 22, 12, 0, 0);
var j = schedule.scheduleJob(date, function(){
console.log('job is running');
});
Upvotes: 3