LoginSignup
17
18

More than 5 years have passed since last update.

nodeでcronを実行する

Last updated at Posted at 2015-08-24

インストール
node-cronをインストールする。

$ npm install --save cron

基本的な使い方は以下の通り。

const {CronJob} = require('cron');

new CronJob('* * * * * *', () => {
  console.log('Hello');
}, null, true);

cronの時間の指定

  • 秒: 0-59
  • 分: 0-59
  • 時: 0-23
  • 日: 1-31
  • 月: 0-11
  • 週: 0-6

週は0が日曜日。
なので月〜金曜日毎日11時30分00秒に実行したければ
new CronJob('00 30 11 * * 1-5')
とする。

17
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
18