node-schedule 的使用

node-schedule 的使用

  1. 在终端输入 npm install node-schedule
  2. 自己的代码中 const schedule = require("node-schedule");
  • 间隔3秒执行一次任务
const schedule = require("node-schedule");
const job = schedule.scheduleJob("*/3 * * * * *", function (fireDate) {
  console.log(
    "每隔3秒就会执行我一次,This job was supposed to run at " +
      fireDate +
      ", but actually ran at " +
      new Date()
  );
});
  • 取消定时任务
job.cancel();

你可能感兴趣的:(node-schedule 的使用)