npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

croot-cron

v0.1.0

Published

Lightweight cron parsing and scheduling utilities.

Readme

CROOT 🕐

Cron Root - A robust cron expression parser and job scheduler for Node.js

Installation

npm install croot

Quick Start

import { CronJob } from 'croot';

// Create a job that runs every 5 minutes
const job = new CronJob('0 */5 * * * *', () => {
  console.log('Running every 5 minutes!');
});

job.start();

// Stop when needed
// job.stop();

Features

  • ✅ Full cron expression support (6 fields with seconds)
  • ✅ Human-readable explanations
  • ✅ Robust validation and error handling
  • ✅ Retry mechanisms for failed jobs
  • ✅ Timezone support
  • ✅ Event-driven architecture
  • ✅ Zero dependencies

Usage Examples

Basic Job Scheduling

import { CronJob } from 'croot';

const job = new CronJob('0 9 * * 1-5', () => {
  console.log('Running at 9 AM on weekdays');
}, {
  retries: 3,
  retryDelay: 1000,
  immediate: true
});

job.start();

Expression Parsing & Validation

import { parseCron, explainCronExpression, validateCronExpression } from 'croot';

// Parse expression
const schedule = parseCron('0 */15 * * * *');

// Get human-readable explanation
const explanation = explainCronExpression('0 0 12 * * 0');
console.log(explanation.description);
// "At second 0 of minute 0 hour 12 every day of month every month day of week 0"

// Validate expressions
const result = validateCronExpression('invalid-expression');
if (!result.valid) {
  console.error(result.error);
}

Check Schedule Times

import { isScheduledTime, getNextRunTime } from 'croot';

const schedule = parseCron('0 0 * * *');
const now = new Date();

// Check if now matches schedule
if (isScheduledTime(schedule, now)) {
  console.log('Time to run!');
}

// Get next execution time
const nextRun = getNextRunTime(schedule);
console.log('Next run:', nextRun);

API Reference

CronJob

const job = new CronJob(expression, handler, options);

Options:

  • retries (number): Number of retry attempts (default: 0)
  • retryDelay (number): Delay between retries in ms (default: 2000)
  • immediate (boolean): Run immediately on start (default: false)
  • timezone (string): Timezone for scheduling (default: 'UTC')

Methods:

  • start() - Start the job scheduler
  • stop() - Stop the job completely
  • runOnce() - Execute immediately (returns Promise)
  • pause() - Pause scheduling
  • resume() - Resume after pause
  • explain() - Get human-readable description
  • getNextSchedule() - Get next scheduled run

Events:

  • start - Job started
  • stop - Job stopped
  • tick - Job executed successfully
  • error - Job execution failed
  • retry - Retry attempt started
  • failed - All retries exhausted

Parser Functions

  • parseCron(expression) - Parse cron expression into object
  • validateCronExpression(expression) - Validate and return result
  • explainCronExpression(expression) - Get human-readable explanation
  • isScheduledTime(schedule, date) - Check if date matches schedule
  • getNextRunTime(schedule, fromDate) - Calculate next execution time
  • getRunTimesBetween(schedule, start, end, limit) - Get all runs in date range

Cron Expression Format

CROOT supports 6-field cron expressions (with seconds):

*    *    *    *    *    *
-    -    -    -    -    -
|    |    |    |    |    |
|    |    |    |    |    +----- Day of week (0 - 7) (0 and 7 = Sunday)
|    |    |    |    +---------- Month (1 - 12)
|    |    |    +--------------- Day of month (1 - 31)
|    |    +-------------------- Hour (0 - 23)
|    +------------------------- Minute (0 - 59)
+------------------------------ Second (0 - 59)

Special Characters:

  • * - Any value
  • , - Value list separator
  • - - Range of values
  • / - Step values

Examples

// Every minute
'* * * * *'

// Every 5 minutes
'0 */5 * * * *'

// Daily at 9:30 AM
'0 30 9 * * *'

// Weekdays at 6 PM
'0 0 18 * * 1-5'

// Every Sunday at midnight
'0 0 0 * * 0'

// Complex: Every 15 minutes from 9 AM to 5 PM on weekdays
'0 */15 9-17 * * 1-5'

License

MIT