node-schedule 的使用
- 在终端输入
npm install node-schedule
- 自己的代码中
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();