Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cron-parser

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-parser

Node.js library for parsing crontab instructions

  • 0.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8M
decreased by-6.26%
Maintainers
1
Weekly downloads
 
Created

What is cron-parser?

The cron-parser npm package is a utility for parsing crontab instructions. It allows users to interpret cron schedule expressions and calculate the next run times for jobs. It is useful for scheduling tasks in Node.js applications.

What are cron-parser's main functionalities?

Parsing Cron Expressions

This feature allows users to parse a cron expression and get the next execution times. The code sample demonstrates how to parse a cron expression that runs every 2 minutes and log the next execution time.

const cronParser = require('cron-parser');

try {
  const interval = cronParser.parseExpression('*/2 * * * *');
  console.log('Date: ', interval.next().toString()); // Get the next date
} catch (err) {
  console.error('Error: ' + err.message);
}

Iterating Over Execution Times

This feature allows users to iterate over the execution times of a cron job. The code sample demonstrates how to get the next 5 execution times for a cron expression that runs at the start of every hour.

const cronParser = require('cron-parser');

try {
  const interval = cronParser.parseExpression('0 * * * *');
  for (let i = 0; i < 5; i++) {
    console.log('Date: ', interval.next().toString()); // Get the next 5 dates
  }
} catch (err) {
  console.error('Error: ' + err.message);
}

Handling Cron Expression with Timezone

This feature allows users to parse a cron expression with a specific timezone. The code sample demonstrates how to parse a cron expression that runs at the start of every hour, considering the timezone of Europe/Amsterdam.

const cronParser = require('cron-parser');

try {
  const options = {
    currentDate: new Date('Wed, 26 Dec 2012 14:38:53 GMT'),
    tz: 'Europe/Amsterdam'
  };
  const interval = cronParser.parseExpression('0 * * * *', options);
  console.log('Date: ', interval.next().toString()); // Get the next date considering timezone
} catch (err) {
  console.error('Error: ' + err.message);
}

Other packages similar to cron-parser

Keywords

FAQs

Package last updated on 04 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc