Javascript & HTML & CSS/NodeJS
node-schedule 을 활용한 스케쥴러 구현
전봉근
2022. 12. 2. 11:08
반응형
- node-schedule 을 활용한 스케쥴러 구현
- module 설치
// https://www.npmjs.com/package/node-schedule $ npm i node-schedule
- 코드
[index.js or app.js]const schedule = require('node-schedule'); const express = require('express'); const app = express(); app.get('/', function (req, res) { res.send('Hello World'); }) app.listen(3000, function(){ console.log('Express start on port 3000!'); schedule.scheduleJob('* * * * * *', function(){ console.log('The answer to life, the universe, and everything!'); }); });
- 스케줄 설정 방법
* * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ │ │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) │ │ │ │ └───── month (1 - 12) │ │ │ └────────── day of month (1 - 31) │ │ └─────────────── hour (0 - 23) │ └──────────────────── minute (0 - 59) └───────────────────────── second (0 - 59, OPTIONAL) 매초 실행 : * * * * * * 매분 실행 : * * * * * 매분 0초에 실행 : 0 * * * * * 매분 10초에 실행 : 10 * * * * * 매시 1분 10초에 실행 : 10 1 * * * *
- module 설치
반응형