What is @types/node-schedule?
@types/node-schedule provides TypeScript definitions for the node-schedule package, which is a flexible cron-like and not-cron-like job scheduler for Node.js.
What are @types/node-schedule's main functionalities?
Scheduling a Job
This feature allows you to schedule a job using a cron-like syntax. In this example, the job is scheduled to run at the 42nd minute of every hour.
const schedule = require('node-schedule');
const job = schedule.scheduleJob('42 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
Canceling a Job
This feature allows you to cancel a scheduled job. In this example, the job is canceled before it has a chance to run.
const schedule = require('node-schedule');
const job = schedule.scheduleJob('42 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
job.cancel();
Rescheduling a Job
This feature allows you to reschedule an existing job. In this example, the job is rescheduled to run at the 10th minute of every hour.
const schedule = require('node-schedule');
const job = schedule.scheduleJob('42 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
job.reschedule('10 * * * *');
Scheduling a Job with Recurrence Rule
This feature allows you to schedule a job using a recurrence rule. In this example, the job is scheduled to run at 5:42 PM on weekdays and Sundays.
const schedule = require('node-schedule');
const rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [0, new schedule.Range(1, 5)];
rule.hour = 17;
rule.minute = 42;
const job = schedule.scheduleJob(rule, function(){
console.log('The answer to life, the universe, and everything!');
});
Other packages similar to @types/node-schedule
node-cron
node-cron is a lightweight task scheduler in pure JavaScript for Node.js based on the cron syntax. It is similar to node-schedule but focuses solely on cron-like scheduling without additional features like recurrence rules.
agenda
agenda is a light-weight job scheduling library for Node.js that uses MongoDB for persistence. It offers more advanced features like job prioritization, job concurrency, and job persistence, making it more suitable for complex scheduling needs compared to node-schedule.
bree
bree is a job scheduler for Node.js with a focus on simplicity and performance. It uses worker threads to run jobs in parallel and supports cron syntax. It is more modern and performant compared to node-schedule.