explaingit

kelektiv/node-cron

8,928TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

node-cron is a Node.js library that schedules code to run at specific times or on repeating intervals using cron syntax, handling everything from daily jobs to sub-second tasks.

Mindmap

mindmap
  root((repo))
    What It Does
      Schedule recurring tasks
      Cron syntax support
      Sub-second precision
      Start and stop jobs
    Tech Stack
      TypeScript
      Node.js
      Luxon
    Use Cases
      Daily email sends
      Database cleanup
      Backup scheduling
    Features
      CronJob class
      Next-run utilities
      Expression validation
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Schedule a Node.js function to send daily emails at 8am using a simple cron expression and time zone setting.

USE CASE 2

Run database cleanup or backup tasks on a recurring weekly schedule inside a Node.js application.

USE CASE 3

Validate cron expressions and preview the next scheduled trigger time before deploying a job to production.

USE CASE 4

Control job start and stop programmatically, enabling dynamic scheduling based on application state or user settings.

Tech stack

TypeScriptNode.jsLuxon

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

node-cron is a TypeScript library for Node.js that lets you schedule code to run automatically at specific times or on repeating schedules. If you want your application to send a daily email at 8am, clean up old files every Sunday, or run a data backup every hour, this library handles that scheduling logic for you. Schedules are written using cron syntax, a compact notation originally from Unix systems. A pattern like 0 8 * means "at 8:00am every day." The library extends the standard five-field format with an optional sixth field for seconds, so you can schedule tasks down to the second if needed. You can also pass a JavaScript Date object or a Luxon DateTime object instead of a cron string if you prefer to work with dates directly. The main building block is the CronJob class. You create a job by providing a schedule, a function to run, and optional settings like the time zone and whether to start the job immediately. Jobs can be started and stopped programmatically. There are also standalone utility functions: one tells you when a given cron expression will next fire, one returns the number of milliseconds until the next trigger, and one validates whether a cron expression is written correctly. Version 3 introduced TypeScript support and aligned month and day-of-week numbering with standard Unix cron conventions. Version 4 dropped support for Node.js 16 and made the job's running-state property read-only. The README includes a migration guide covering the specific changes between major versions. The library works with Node.js 18 and above and is available on npm. It is a common choice for background task scheduling in Node.js applications.

Copy-paste prompts

Prompt 1
Show me how to create a CronJob in node-cron that runs a database cleanup function every Sunday at midnight in the America/New_York time zone.
Prompt 2
Write a node-cron job that sends an API request every 30 seconds and logs the response, with the ability to pause and resume the job.
Prompt 3
How do I use node-cron's utility functions to validate a cron expression and find out exactly when it will next fire?
Prompt 4
Help me migrate a node-cron v2 job to v3, handling the changes in month numbering and the new TypeScript types.
Open on GitHub → Explain another repo

← kelektiv on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.