Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

croner

> 编程语言
Open source

Trigger functions or evaluate cron expressions in JavaScript or TypeScript. No dependencies. Most features. Node. Deno. Bun. Browser.

2.6K stars0 likes1 views
WebsiteGitHub

About

Trigger functions or evaluate cron expressions in JavaScript or TypeScript. No dependencies. Most features. Node. Deno. Bun. Browser.


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.
  • Supports seconds and 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:

…

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 cron or node-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

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

// ... or CommonJS Require, destructure to add type hints
const { Cron } = require("croner");

Using Deno

typescript
// From deno.land/x
import { Cron } from "https://deno.land/x/[email protected]/dist/croner.js";

// ... or jsr.io
import { Cron } from "jsr:@hexagon/[email protected]";

In a webpage using the UMD-module

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

Documentation

Signature

Cron takes three arguments

  • pattern
  • options (optional)
  • scheduled function (optional)
javascript
// 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

…

Control functions

javascript
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

javascript
job.name 			// Optional job name, populated if a name were passed to options

Options

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 uses Vixie Cron based expressions with the following powerful extensions:

javascript
// ┌──────────────── (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)
// │ │ │ │ │ │ │
// * * * * * * *
  • 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
  • Advanced calendar modifiers:

    • L: Last day of month or last occurrence of a weekday. L in day-of-month = last day of month; 5#L or FRI#L = last Friday of the month.
    • W: Nearest weekday. 15W triggers 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.
  • 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 * +MON only 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.
  • 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. Example: 0 20 1 * MON triggers on the 1st of the month OR on Mondays. Use the + modifier (0 20 1 * +MON) or { domAndDow: true } for AND logic. For more information, see issue #53.

Field Required Allowed values Allowed special characters Remarks
Seconds Optional 0-59 * , - / ? 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
Year Optional 1-9999 * , - / Optional, defaults to *

Note Weekday and month names are case-insensitive. Both MON and mon work. When using L in the Day of Week field with a range, it affects all specified weekdays. For example, 5-6#L means 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. The W character operates within the current month and won't cross month boundaries. If the 1st is a Saturday, 1W matches Monday the 3rd. The + modifier (OCPS 1.4) enforces AND logic: 0 12 1 * +MON only runs when the 1st is also a Monday. Quartz mode: Enable alternativeWeekdays: true to 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.

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 |

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptcroncrontabcrontab-syntaxdeno

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言