Explain and validate cron expressions in human-readable format
Format: minute hour day month weekday
Cron Expression Format:
Special Characters:
* - Any value, - Value list separator (e.g., 1,3,5)- - Range of values (e.g., 1-5)/ - Step values (e.g., */15 = every 15)0 0 * * *- Daily at midnight0 */2 * * *- Every 2 hours30 9 * * 1-5- Weekdays at 9:30 AM0 0 1 * *- First day of every month*/15 * * * *- Every 15 minutes0 9-17 * * 1-5- Every hour from 9 AM to 5 PM on weekdaysCron expression helper translates between human-readable schedules and cron syntax (the standard for scheduling tasks on Unix systems). Cron uses a compact 5-field format to specify when jobs run: minute, hour, day of month, month, and day of week.
Each cron field accepts: specific values (5), ranges (1-5), lists (1,3,5), steps (*/5), and wildcards (*). The scheduler checks if current time matches all fields. Special strings like @daily and @hourly provide shortcuts. The helper parses expressions and shows upcoming execution times.
Standard cron: "minute hour day month weekday" (0-59, 0-23, 1-31, 1-12, 0-7). Extended format adds seconds and year fields. Day-of-week: 0/7=Sunday, 1=Monday. Month/day names allowed in some implementations. Timezone handling varies by system - use UTC when possible.
Run database backups every night at 2 AM.
0 2 * * * /scripts/backup.sh (daily at 2:00 AM)Generate weekly reports every Monday morning.
Clear application caches every hour.
Run system health checks every 5 minutes.
Synchronize data between systems at scheduled intervals.
# Every minute
* * * * *
# Every hour at minute 0
0 * * * *
# Daily at midnight
0 0 * * *
# Every Monday at 9 AM
0 9 * * 1
# Every 15 minutes
*/15 * * * *
# First day of month at midnight
0 0 1 * *
# Weekdays at 6 PM
0 18 * * 1-5
# Every 6 hours
0 */6 * * *
# Twice daily (9 AM and 6 PM)
0 9,18 * * *Format: minute (0-59) hour (0-23) day (1-31) month (1-12) weekday (0-7, 0/7=Sun)
// Using cron-parser library
import parser from 'cron-parser';
const interval = parser.parseExpression('0 9 * * 1-5');
// Get next execution times
console.log(interval.next().toString());
console.log(interval.next().toString());
// Using node-cron to schedule
import cron from 'node-cron';
cron.schedule('*/5 * * * *', () => {
console.log('Running every 5 minutes');
});
// Validate cron expression
cron.validate('0 * * * *'); // true
cron.validate('invalid'); // falsecron-parser calculates execution times. node-cron schedules actual jobs in Node.js applications.
Use cron expressions for any scheduled task: backups, report generation, cache clearing, data synchronization, health checks, or any recurring job that needs to run at specific times.
*/5 * * * * - the */5 means "every 5th value" in the minutes field. This runs at :00, :05, :10, :15, etc. For every 5 hours: 0 */5 * * *