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 ,
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?
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./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?
Share Improve this question asked Jan 16, 2018 at 4:55 shamon shamsudeenshamon shamsudeen 5,85820 gold badges74 silver badges144 bronze badges2 Answers
Reset to default 3for 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');
});
You can pass date object in it. if you read document further you will find it here : https://www.npmjs./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.');
});