traceflow-cron
v1.0.0
Published
Lightweight TypeScript cron scheduler
Readme
Traceflow Cron
Lightweight and simple cron scheduler for Node.js & TypeScript.
Built on top of node-cron with a clean developer-friendly API.
Installation
npm install traceflow-cronFeatures
- Simple cron scheduling
- TypeScript support
- Multiple job management
- Start / Stop jobs
- Lightweight
- Easy integration
Usage
Basic Example
import { TraceflowCron } from "traceflow-cron";
const cron = new TraceflowCron();
cron.schedule(
"daily-task",
"0 2 * * *",
() => {
console.log("Runs every day at 2 AM");
}
);Cron Expression Format
* * * * *
| | | | |
| | | | └─ Day of week
| | | └── Month
| | └──── Day
| └────── Hour
└──────── MinuteExamples
Every Day at 2 AM
cron.schedule(
"night-job",
"0 2 * * *",
() => {
console.log("Night task");
}
);Every 5 Seconds
cron.schedule(
"test-job",
"*/5 * * * * *",
() => {
console.log("Runs every 5 seconds");
}
);Every Monday at 9 AM
cron.schedule(
"weekly-report",
"0 9 * * 1",
() => {
console.log("Weekly report");
}
);API
schedule(name, expression, callback)
Create a new cron job.
cron.schedule(
"backup",
"0 0 * * *",
() => {}
);| Parameter | Type | Description | | ---------- | -------- | ------------------- | | name | string | Unique job name | | expression | string | Cron expression | | callback | function | Function to execute |
stop(name)
Stop a running job.
cron.stop("backup");start(name)
Restart a stopped job.
cron.start("backup");destroy(name)
Remove a job completely.
cron.destroy("backup");getJobs()
Get all registered jobs.
console.log(cron.getJobs());TypeScript Support
Fully typed with declaration files included.
License
MIT
Author
Built with ❤️ by Lokith
