node-cron
Cron-style task scheduler for Node.js that runs functions on a crontab expression inside the event loop.
Official Documentation ↗node-cron v3.x / Node 18 LTS. Check the official docs for the latest API surface.Installation
npm install node-cronpnpm add node-cronyarn add node-cronMethods
No methods match this filter.
Overview
node-cron lets a Node process run recurring work on crontab-style schedules without an external cron daemon. Tasks live in the event loop, so they only run while the process is alive, which suits long-running services.
Core Methods
cron.schedule returns a task handle that can be started, stopped or destroyed. cron.validate guards against malformed expressions, and timezone and scheduled options refine when a task fires.
Usage Notes
Keep job bodies short and delegate heavy work to a queue so a long task cannot block the event loop. Register schedules at startup and expose the handles so shutdown can stop them cleanly.
Common Pitfalls
Schedules are not persisted; a restart forgets them until re-registered. Overlapping runs can stack if a job takes longer than its interval, so add a guard flag or a lock. Local timezone surprises cause off-by-one-hour executions around DST.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/node-cron/node-cron@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:10.469Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Otherwise the fork fails with Cannot find module ‘…/daemon.js’. (https://cdn.jsdelivr.net/gh/node-cron/node-cron@latest/README.md)
FAQ
- Does node-cron support seconds?
- Yes. A six-field expression adds seconds as the leftmost field, so "*/10 * * * * *" runs every ten seconds. A five-field expression is the classic minute resolution.
- What timezone is used?
- By default the machine local time is used. Version 3 accepts a timezone option so tasks fire according to a named zone, which matters for nightly jobs and daylight saving.
- What happens if a task throws?
- An uncaught throw inside the callback can crash the process. Wrap the job body in try/catch and log failures so one bad run does not take the scheduler down.
Report a problem with this API docOpens a pre-filled issue on GitHub.