cron-parser is a robust Node.js library for parsing, validating, and iterating over cron expressions. It currently stands at stable version 5.5.0 and demonstrates a consistent release cadence with frequent updates addressing bug fixes, performance improvements, and new features like the `H` (hashed value) syntax. Key differentiators include comprehensive timezone support, intelligent handling of Daylight Saving Time (DST), and an iterator-based API for easily generating future schedule dates. It supports both standard cron formats and several special characters like `L` (last day), `#` (nth day of week), and `H` (randomized values), alongside predefined expressions such as `@daily` and `@hourly`. The library is ESM-first and requires Node.js >= 18 and TypeScript >= 5.
npm install cron-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a cron expression, specify timezone options, and iterate through the next scheduled dates using the `parseExpression` function and `CronExpression` iterator.
Review the pull request #379 for detailed changes. If directly constructing `CronField` objects, adapt to the new constructor signature. If using `nthDayOfWeek` in options, find an alternative approach or ensure your cron expression implicitly handles it.
For versions before 5.0.5, always explicitly specify the `tz` option in `CronOptions` if you need a specific timezone, or update to v5.0.5 or later to use the system's local timezone by default for `currentDate`.
Ensure you are using `cron-parser` version 5.1.1 or newer to benefit from the fix for last day of month handling when an explicit month is set.
Update to version 5.3.1 or newer to ensure correct validation and parsing of cron expressions involving start and end date spans.
Double-check the cron expression against the documentation for valid fields, ranges, and special characters. Ensure all required fields (minute, hour, day of month, month, day of week, and optional second) are present and correctly formatted.
Change `const { parseExpression } = require('cron-parser');` to `import { parseExpression } from 'cron-parser';`. Ensure your environment supports ES Modules or transpile your code if necessary.Run `npm install cron-parser` or `yarn add cron-parser`. For TypeScript, ensure `esModuleInterop` is `true` in your `tsconfig.json` if encountering issues with default/named imports, though `cron-parser` provides types.