Sometimes it may help if you need to do something in the morning, depending on your business needs, and I'm looking at this recently, and welcome to discuss it together.
GitHub Address: Https://github.com/mattpat/node-schedule
First, installation
Copy Code code as follows:
NPM Install Node-schedule
Ii. determination of time, for example: November 21, 2012, 5:30
Copy Code code as follows:
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's going to end today. ');
});
Cancel a preset schedule
[Code]
J.cancel ();
Three, fixed minutes per hour, for example: 42 minutes per hour
Copy Code code as follows:
var schedule = require (' Node-schedule ');
var rule = new schedule. Recurrencerule ();
Rule.minute = 42;
var j = schedule.schedulejob (rule, function () {
Console.log (' The answer to life, the universe, and everything! ');
});
Iv. Some of the days of the one week, for example: every Thursday, Friday, Saturday, Sunday 17.
Copy Code code as follows:
var rule = new schedule. Recurrencerule ();
Rule.dayofweek = [0, new schedule. Range (4, 6)];
Rule.hour = 17;
Rule.minute = 0;
var j = schedule.schedulejob (rule, function () {
Console.log (' is recognized by Rebecca black! ');
});
Five, per second execution
Copy Code code as follows:
var rule = new schedule. Recurrencerule ();
var times = [];
for (var i=1; i<60; i++) {
Times.push (i);
}
Rule.second = times;
var c=0;
var j = schedule.schedulejob (rule, function () {
C + +;
Console.log (c);
});