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4.3.5
- 4.3.4
- 4.3.3
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.97
- 4.1.96
- 4.1.95
- 4.1.94
- 4.1.93
- 4.1.92
- 4.1.91
- 4.0.90
- 4.0.89
- 4.0.88
- 4.0.87
- 4.0.86
- 4.0.85
- 4.0.84
- 4.0.83
- 4.0.82
- 4.0.81
- 4.0.80
- 4.0.79
- 4.0.78
- 4.0.77
- 4.0.76
- 4.0.75
- 4.0.74
- 4.0.73
- 4.0.72
- 4.0.71

Trigger functions or evaluate cron expressions in JavaScript or TypeScript. No dependencies. All features. Node. Deno. Bun. Browser.
Try it live on jsfiddle, and check out the full documentation on croner.56k.guru.
Croner - Cron for JavaScript and TypeScript
- Trigger functions in JavaScript using Cron syntax.
- Evaluate cron expressions and get a list of upcoming run times.
- OCPS 1.0-1.4 compliant: Fully supports the Open Cron Pattern Specification including advanced features like seconds/year fields,
L(last),W(weekday),#(nth occurrence), and+(AND logic). - Works in Node.js >=18.0 (both require and import), Deno >=2.0 and Bun >=1.0.0.
- Works in browsers as standalone, UMD or ES-module.
- Target different time zones.
- Built-in overrun protection
- Built-in error handling
- Includes TypeScript typings.
- Support for asynchronous functions.
- Pause, resume, or stop execution after a task is scheduled.
- Operates in-memory, with no need for a database or configuration files.
- Zero dependencies.
Quick examples:
// Basic: Run a function at the interval defined by a cron expression
const job = new Cron('*/5 * * * * *', () => {
console.log('This will run every fifth second');
});
// Enumeration: What dates do the next 100 sundays occur on?
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 (time is ISO 8601 local time)
// 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!') });
// Check if a date matches a cron pattern
const mondayCheck = new Cron('0 0 0 * * MON');
console.log(mondayCheck.match('2024-01-01T00:00:00')); // true (Monday)
console.log(mondayCheck.match('2024-01-02T00:00:00')); // false (Tuesday)
More examplesβ¦
Installation
Full documentation on installation and usage is found at https://croner.56k.guru
Note If you are migrating from a different library such as
cronornode-cron, or upgrading from a older version of croner, see the migration section of the manual.
Install croner using your favorite package manager or CDN, then include it in you project:
Using Node.js or Bun
// ESM Import ...
import { Cron } from "croner";
// ... or CommonJS Require, destructure to add type hints
const { Cron } = require("croner");Using Deno
// From deno.land/x
import { Cron } from "https://deno.land/x/croner@10.0.0/dist/croner.js";
// ... or jsr.io
import { Cron } from "jsr:@hexagon/croner@10.0.0";In a webpage using the UMD-module
<script src="https://cdn.jsdelivr.net/npm/croner@10/dist/croner.umd.min.js"></script>Documentation
Signature
Cron takes three arguments
// Parameters
// - First: Cron pattern, js date object (fire once), or ISO 8601 time string (fire once)
// - Second: Options (optional)
// - Third: Function run trigger (optional)
const job = new Cron("* * * * * *", { maxRuns: 1 }, () => {} );
// If function is omitted in constructor, it can be scheduled later
job.schedule(job, /* optional */ context) => {});The job will be sceduled to run at next matching time unless you supply option { paused: true }. The new Cron(...) constructor will return a Cron instance, later called job, which have a couple of methods and properties listed below.
Status
job.nextRun( /*optional*/ startFromDate ); // Get a Date object representing the next run.
job.nextRuns(10, /*optional*/ startFromDate ); // Get an array of Dates, containing the next n runs.
job.previousRuns(10, /*optional*/ referenceDate ); // Get an array of Dates, containing previous n scheduled runs.
job.msToNext( /*optional*/ startFromDate ); // Get the milliseconds left until the next execution.
job.currentRun(); // Get a Date object showing when the current (or last) run was started.
job.previousRun( ); // Get a Date object showing when the previous job was started.
job.match( date ); // Check if a Date object or date string matches the cron pattern (true or false).
job.isRunning(); // Indicates if the job is scheduled and not paused or killed (true or false).
job.isStopped(); // Indicates if the job is permanently stopped using `stop()` (true or false).
job.isBusy(); // Indicates if the job is currently busy doing work (true or false).
job.getPattern(); // Returns the original pattern string
job.getOnce(); // Returns the original run-once date (Date or null)Control functions
job.trigger(); // Force a trigger instantly
job.pause(); // Pause trigger
job.resume(); // Resume trigger
job.stop(); // Stop the job completely. It is not possible to resume after this.
// Note that this also removes named jobs from the exported `scheduledJobs` array.Properties
job.name // Optional job name, populated if a name were passed to optionsOptions
| Key | Default value | Data type | Remarks |
|---|---|---|---|
| name | undefined | String | If you specify a name for the job, Croner will keep a reference to the job in the exported array scheduledJobs. The reference will be removed on .stop(). |
| maxRuns | Infinite | Number | |
| catch | false | Boolean|Function | Catch unhandled errors in triggered function. Passing true will silently ignore errors. Passing a callback function will trigger this callback on error. |
| timezone | undefined | String | Timezone in Europe/Stockholm format |
| startAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00) in local time (according to timezone parameter if passed) |
| stopAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00) in local time (according to timezone parameter if passed) |
| interval | 0 | Number | Minimum number of seconds between triggers. |
| paused | false | Boolean | If the job should be paused from start. |
| context | undefined | Any | Passed as the second parameter to triggered function |
| domAndDow | false | boolean | Combine day-of-month and day-of-week using true = AND, false = OR (default) |
| legacyMode | (deprecated) | boolean | Deprecated: Use domAndDow instead. Inverse of domAndDow (legacyMode: true = domAndDow: false). |
| unref | false | boolean | Setting this to true unrefs the internal timer, which allows the process to exit even if a cron job is running. |
| utcOffset | undefined | number | Schedule using a specific utc offset in minutes. This does not take care of daylight savings time, you probably want to use option timezone instead. |
| protect | undefined | boolean|Function | Enabled over-run protection. Will block new triggers as long as an old trigger is in progress. Pass either true or a callback function to enable |
| alternativeWeekdays | false | boolean | Enable Quartz-style weekday numbering (1=Sunday, 2=Monday, β¦, 7=Saturday). When false (default), uses standard cron format (0=Sunday, 1=Monday, β¦, 6=Saturday). |
Warning Unreferencing timers (option
unref) is only supported by Node.js and Deno. Browsers have not yet implemented this feature, and it does not make sense to use it in a browser environment.
Pattern
Croner is fully compliant with the Open Cron Pattern Specification (OCPS) versions 1.0 through 1.4. The expressions are based on Vixie Cron with powerful extensions:
// βββββββββββββββββ (optional) second (0 - 59)
// β βββββββββββββββ minute (0 - 59)
// β β βββββββββββββ hour (0 - 23)
// β β β βββββββββββ day of month (1 - 31)
// β β β β βββββββββ month (1 - 12, JAN-DEC)
// β β β β β βββββββ day of week (0 - 6, SUN-Mon)
// β β β β β β (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0)
// β β β β β β βββββ (optional) year (1 - 9999)
// β β β β β β β
// * * * * * * *OCPS 1.2: Optional second and year fields for enhanced precision:
- 6-field format:
SECOND MINUTE HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK - 7-field format:
SECOND MINUTE HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK YEAR - Supported year range: 1-9999
- 6-field format:
OCPS 1.3: Advanced calendar modifiers:
- L: Last day of month or last occurrence of a weekday.
Lin day-of-month = last day of month;5#LorFRI#L= last Friday of the month. - W: Nearest weekday.
15Wtriggers on the weekday closest to the 15th (moves to Friday if 15th is Saturday, Monday if 15th is Sunday). Wonβt cross month boundaries. - #: Nth occurrence of a weekday.
5#2= second Friday;MON#1= first Monday of the month.
- L: Last day of month or last occurrence of a weekday.
OCPS 1.4: Enhanced logical control:
- +: Explicit AND logic modifier. Prefix the day-of-week field with
+to require both day-of-month AND day-of-week to match. Example:0 12 1 * +MONonly triggers when the 1st is also a Monday. - ?: Wildcard alias (behaves identically to
*). Non-portable: Its use is discouraged in patterns intended for cross-system use. Supported in all fields for compatibility, but primarily meaningful in day-of-month and day-of-week fields. - Proper DST handling: Jobs scheduled during DST gaps are skipped; jobs in DST overlaps run once at first occurrence.
- +: Explicit AND logic modifier. Prefix the day-of-week field with
Croner allows you to pass a JavaScript Date object or an ISO 8601 formatted string as a pattern. The scheduled function will trigger at the specified date/time and only once. If you use a timezone different from the local timezone, you should pass the ISO 8601 local time in the target location and specify the timezone using the options (2nd parameter).
By default, Croner uses OR logic for day-of-month and day-of-week (OCPS 1.0 compliant). Example:
0 20 1 * MONtriggers on the 1st of the month OR on Mondays. Use the+modifier (0 20 1 * +MON) or{ domAndDow: true }for AND logic (OCPS 1.4 compliant). For more information, see issue #53.
| Field | Required | Allowed values | Allowed special characters | Remarks |
|---|---|---|---|---|
| Seconds | Optional | 0-59 | * , - / ? | OCPS 1.2: Optional, defaults to 0 |
| Minutes | Yes | 0-59 | * , - / ? | |
| Hours | Yes | 0-23 | * , - / ? | |
| Day of Month | Yes | 1-31 | * , - / ? L W | L = last day, W = nearest weekday |
| Month | Yes | 1-12 or JAN-DEC | * , - / ? | |
| Day of Week | Yes | 0-7 or SUN-MON | * , - / ? L # + | 0 and 7 = Sunday (standard mode) 1-7 = Sunday-Saturday (Quartz mode with alternativeWeekdays: true)# = nth occurrence (e.g. MON#2) + = AND logic modifier (OCPS 1.4) |
| Year | Optional | 1-9999 | * , - / | OCPS 1.2: Optional, defaults to * |
Note Weekday and month names are case-insensitive. Both
MONandmonwork. When usingLin the Day of Week field with a range, it affects all specified weekdays. For example,5-6#Lmeans the last Friday and Saturday in the month. The#character specifies the βnthβ weekday of the month. For example,5#2= second Friday,MON#1= first Monday. TheWcharacter operates within the current month and wonβt cross month boundaries. If the 1st is a Saturday,1Wmatches Monday the 3rd. The+modifier (OCPS 1.4) enforces AND logic:0 12 1 * +MONonly runs when the 1st is also a Monday. Quartz mode: EnablealternativeWeekdays: trueto use Quartz-style weekday numbering (1=Sunday, 2=Monday, β¦, 7=Saturday) instead of the standard format (0=Sunday, 1=Monday, β¦, 6=Saturday). This is useful for compatibility with Quartz cron expressions.
OCPS 1.1: Predefined schedule nicknames are supported:
| Nickname | Description |
|---|---|
| @yearly / @annually | Run once a year, i.e. β0 0 1 1 *β. |
| @monthly | Run once a month, i.e. β0 0 1 * *β. |
| @weekly | Run once a week, i.e. β0 0 * * 0β. |
| @daily / @midnight | Run once a day, i.e. β0 0 * * *β. |
| @hourly | Run once an hour, i.e. β0 * * * *β. |
Why another JavaScript cron implementation
Because the existing ones are not good enough. They have serious bugs, use bloated dependencies, do not work in all environments, and/or simply do not work as expected.
For example, some popular alternatives include large datetime libraries as dependencies, which significantly increases bundle size. Croner has zero dependencies and a much smaller footprint, making it ideal for applications where bundle size matters.
| croner | cronosjs | node-cron | cron | node-schedule | |
|---|---|---|---|---|---|
| Platforms | |||||
| Node.js (CommonJS) | β | β | β | β | β |
| Browser (ESMCommonJS) | β | β | |||
| Deno (ESM) | β | ||||
| Features | |||||
| Over-run protection | β | ||||
| Error handling | β | β | |||
| Typescript typings | β | β | β | ||
| Unref timers (optional) | β | β | |||
| dom-OR-dow | β | β | β | β | β |
| dom-AND-dow (optional) | β | ||||
| Next run | β | β | β | β | |
| Next n runs | β | β | β | ||
| Timezone | β | β | β | β | β |
| Minimum interval | β | ||||
| Controls (stop/resume) | β | β | β | β | β |
| Range (0-13) | β | β | β | β | β |
| Stepping (*/5) | β | β | β | β | β |
| Seconds field (OCPS 1.2) | β | ||||
| Year field (OCPS 1.2) | β | ||||
| Last day of month (L) | β | β | |||
| Nth weekday of month (#) | β | β | |||
| Nearest weekday (W) | β | β | |||
| AND logic modifier (+) | β |
In depth comparison of various libraries
| croner | cronosjs | node-cron | cron | node-schedule | |
|---|---|---|---|---|---|
| Size | |||||
| Minified size (KB) | 22.7 | 14.9 | 20.1 | 93.7 β οΈ | 107.8 β οΈ |
| Bundlephobia minzip (KB) | 6.8 | 5.1 | 6.1 | 28.2 | 31.2 β οΈ |
| Dependencies | 0 | 0 | 1 | 1 | 3 β οΈ |
| Popularity | |||||
| Downloads/week [^1] | 2019K | 31K | 447K | 1366K | 1046K |
| Quality | |||||
| Issues [^1] | 0 | 2 | 133 β οΈ | 13 | 145 β οΈ |
| Code coverage | 99% | 98% | 100% | 81% | 94% |
| Performance | |||||
Ops/s 1 2 3 4 5 6 |
160 651 | 55 593 | N/A :x: | 6 313 β οΈ | 2 726 β οΈ |
Ops/s 0 0 0 29 2 * |
176 714 | 67 920 | N/A :x: | 3 104 β οΈ | 737 β οΈ |
| Tests | 11/11 | 10/11 | 0/11 [^4] :question: | 7/11 β οΈ | 9/11 |
Note
- Table last updated at 2023-10-10
- node-cron has no interface to predict when the function will run, so tests cannot be carried out.
- All tests and benchmarks were carried out using https://github.com/Hexagon/cron-comparison
[^1]: As of 2023-10-10 [^2]: Requires support for L-modifier [^3]: In dom-AND-dow mode, only supported by croner at the moment. [^4]: Node-cron has no way of showing next run time.
Development
Master branch
This branch contains the latest stable code, released on npmβs default channel latest. You can install the latest stable revision by running the command below.
npm install croner --saveDev branch
This branch contains code currently being tested, and is released at channel dev on npm. You can install the latest revision of the development branch by running the command below.
npm install croner@devWarning Expect breaking changes if you do not pin to a specific version.
A list of fixes and features currently released in the dev branch is available here
Contributing & Support
Croner is founded and actively maintained by Hexagon. If you find value in Croner and want to contribute:
Code Contributions: See our Contribution Guide for details on how to contribute code.
Sponsorship and Donations: See github.com/sponsors/hexagon
Your trust, support, and contributions drive the project. Every bit, irrespective of its size, is deeply appreciated.
License
MIT License