[note] node-cron 筆記
keywords: cron table
, 排程
node-cron @ github
使用
排程的任務會是整個 js 檔執行完後才開始:
const cron = require('node-cron');
/**
* 基本使用
* 第一個參數:排成格式
* 第二個參數:要執行的 function
* 第三個參數:是否要立即執行
**/
let task = cron.schedule(
'* * * * * *',
function () {
console.log('hello world', counter, new Date().getSeconds());
},
true,
);
task.start();
task.stop();
task.destroy();
/**
* 檢驗是否是有效的排程格式
**/
cron.validate('* * * * * *');