一、安装

  1. npm install node-schedule

二、设置定时任务

  1. const schedule = require('node-schedule');
  2. var rule = new schedule.RecurrenceRule();
  3. var time1 = [0, 10, 20, 30, 40, 50] //10倍整数
  4. var time2 = [0, 20, 40] //20倍整数
  5. var time3 = [0, 30] //30倍整数
  6. rule.second = time1//秒 代表每10秒执行一次
  7. // rule.minute = time3//分 每30分执行一次
  8. schedule.scheduleJob(rule, () => {
  9. console.log('scheduleCronstyle:' + new Date());
  10. })