Node Schedule is a robust and flexible job scheduler for Node.js, designed for time-based scheduling rather than simple intervals. It enables developers to execute arbitrary functions at specific dates and times, supporting intricate recurrence rules similar to cron, as well as one-off scheduled events. The current stable version is 2.1.1. The library differentiates itself by using only a single timer for all scheduled jobs, optimizing resource usage. Unlike traditional `cron`, it offers cross-platform support, including Windows, due to its JavaScript implementation. It's crucial to understand that `node-schedule` is an in-process scheduler, meaning jobs only run as long as the Node.js process is active and are not persisted across application restarts. For persistent or distributed job scheduling, alternatives like Agenda or Bree should be considered.
npm install node-scheduleVerified import paths — ran on the pinned version, not inferred.
Schedules a recurring job using cron syntax and a one-time job for a future date, demonstrating job creation, event handling, and basic usage.
Upgrade your Node.js runtime to version 6 or newer to ensure compatibility and stability.
Refactor job definitions to pass a function directly or instantiate a `Job` object explicitly, then schedule it. For example, `scheduleJob(rule, () => {})` instead of `scheduleJob({ rule: rule, job: () => {} })`.For durable or persistent jobs that need to survive application restarts or run in multi-node environments, consider using external solutions like actual `cron`, `Agenda`, or `Bree`.
Evaluate if your scheduling needs are truly time-based. For simple recurring intervals, consider `toad-scheduler` or native Node.js timers (`setInterval`) for better fit and potentially simpler implementation.
Ensure your event listeners correctly subscribe to `job.on('canceled', ...)`.Ensure you are using `import { scheduleJob } from 'node-schedule';` for ESM or `const schedule = require('node-schedule'); schedule.scheduleJob(...)` for CommonJS.For jobs that must persist across application restarts, use a durable job scheduler like `Agenda` or `Bree`, or consider system-level `cron`.
Double-check your cron pattern against standard cron format. Ensure that your job callbacks are asynchronous or quickly executed to avoid blocking the event loop. For complex or long-running tasks, consider offloading them to worker threads or separate processes.
Upgrade to `node-schedule` version 2.0.0 or later, as these issues were addressed in that release.
No dependency data recorded yet.