Cron Jobs
Smallweb supports scheduled tasks using cron syntax. Define a run handler and configure the schedule.
Basic Cron Job
Create an app with a run handler:
// ~/smallweb/my-cron/main.ts
export default {
run: () => {
console.log("Cron job executed at", new Date().toISOString());
// Your scheduled task logic here
}
}
Configure the Schedule
Add a smallweb.json file to configure the cron schedule:
{
"cron": "0 * * * *"
}
This runs the job every hour at minute 0.
Cron Syntax
Standard cron syntax is supported:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *
Examples
*/5 * * * *- Every 5 minutes0 9 * * 1-5- 9 AM on weekdays0 0 1 * *- First day of every month at midnight