1.0.2 โข Published 8 months ago
@cronmate/scheduler v1.0.2
๐ TypeScript Scheduler
A simple, developer-friendly, async-aware scheduler for Node.js, built with TypeScript, node-cron, and moment-timezone.
โ Features
- โฑ Easy-to-use methods like
.runEveryMinute(),.runDailyAt(), etc. - ๐ Full timezone support using IANA timezones (e.g.,
"America/New_York") - ๐ง Type-safe: auto-complete for valid timezone strings
- ๐ Async/await ready
- ๐จ Colorful console output with
chalk - ๐งช Returns
ScheduledTaskso you can.stop()manually
๐ Installation
npm install @cronmate/scheduler๐ Usage
import Scheduler from "@cronmate/scheduler";
const scheduler = new Scheduler("Europe/Belgrade");
// Run every second
scheduler.runEverySecond(async () => {
console.log("Hello every second!");
});
// Run daily at 9:30 AM
scheduler.runDailyAt(9, 30, async () => {
await sendDailyEmails();
});๐งฉ API
Constructor
new Scheduler(timezone?: Timezone)timezoneis optional and defaults to your system timezone.- Fully type-safe and auto-suggested.
Schedule Methods
| Method | Runs at |
|---|---|
runEverySecond(fn) | Every second |
runEveryMinute(fn) | Every minute |
runEveryHour(fn) | At the start of every hour |
runEveryDay(fn) | At midnight every day |
runEveryWeek(fn) | Every Sunday at midnight |
runEveryMonth(fn) | On the 1st of every month at 00:00 |
runDailyAt(h, m, fn) | Every day at specific hour & minute |
๐ Stopping a Job
const task = await scheduler.runEveryMinute(() => {
console.log("Ping");
});
task.stop(); // stops the scheduled job๐ง Credits
- Built with
node-cron - Timezone support from
moment-timezone - Logging with
chalk
๐ License
MIT