Croner: A Robust, Dependency-Free Cron Scheduler for JavaScript and TypeScript

Croner: A Robust, Dependency-Free Cron Scheduler for JavaScript and TypeScript

Summary

Croner is a versatile and dependency-free library designed to trigger functions or evaluate cron expressions across various JavaScript environments. It offers comprehensive features, including advanced cron syntax, timezone support, and overrun protection, making it a reliable choice for task scheduling. Compatible with Node.js, Deno, Bun, and browsers, Croner provides a high-performance and lightweight solution for your scheduling needs.

Repository Info

Updated on November 30, 2025
View on GitHub

Tags

Click on any tag to explore related repositories

Introduction

Croner is an exceptional JavaScript and TypeScript library for handling cron expressions and scheduling tasks. It stands out for its zero dependencies, comprehensive feature set, and broad compatibility across Node.js, Deno, Bun, and browser environments. Whether you need to trigger functions at specific intervals or evaluate upcoming run times, Croner provides a robust and efficient solution.

This library supports a Vixie-cron-like pattern with additional modifiers like L for the last day/weekday of the month and # for the nth weekday. It also offers advanced features such as timezone targeting, built-in overrun protection, and error handling, all while maintaining a small footprint.

Installation

Getting started with Croner is straightforward. You can install it using your preferred package manager or include it directly in your web page via a CDN.

Using Node.js or Bun:

// ESM Import
import { Cron } from "croner";

// CommonJS Require
const { Cron } = require("croner");

Using Deno:

// From deno.land/x
import { Cron } from "https://deno.land/x/croner@9.1.0/dist/croner.js";

// From jsr.io
import { Cron } from "jsr:@hexagon/croner@9.1.0";

In a webpage using the UMD-module:

<script src="https://cdn.jsdelivr.net/npm/croner@9/dist/croner.umd.min.js"></script>

Examples

Croner offers intuitive ways to schedule tasks and query cron expressions. Here are a few quick examples to illustrate its usage:

Basic: Run a function every fifth second

const job = new Cron('*/5 * * * * *', () => {
	console.log('This will run every fifth second');
});

Enumeration: Find the next 100 Sundays

const nextSundays = new Cron('0 0 0 * * 7').nextRuns(100);
console.log(nextSundays);

Days left to a specific date

const msLeft = new Cron('59 59 23 24 DEC *').nextRun() - new Date();
console.log(Math.floor(msLeft/1000/3600/24) + " days left to next christmas eve");

Run a function at a specific date/time using a non-local timezone

// This will run 2024-01-23 00:00:00 according to the time in Asia/Kolkata
new Cron('2024-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });

For more detailed examples and advanced usage, refer to the official documentation.

Why use Croner?

Croner addresses common shortcomings found in other JavaScript cron implementations. Many existing libraries suffer from serious bugs, rely on bloated dependencies, lack multi-environment support, or simply don't work as expected. Croner was built to overcome these issues, offering several compelling advantages:

  • Zero Dependencies: Keeps your project lightweight and reduces potential security vulnerabilities.
  • Multi-Platform Support: Works seamlessly across Node.js, Deno, Bun, and modern browsers.
  • Comprehensive Features: Includes advanced cron syntax (with L and # modifiers), timezone support, overrun protection, and robust error handling.
  • Performance and Quality: Benchmarks show Croner significantly outperforms many alternatives in operations per second, while maintaining high code coverage and a minimal issue count.
  • Flexibility: Offers control functions like pause, resume, and stop, along with options for combining day-of-month and day-of-week conditions (AND/OR logic).

Its commitment to quality, performance, and broad compatibility makes Croner a superior choice for reliable task scheduling in JavaScript and TypeScript projects.

Links