Introduction to cron-expression-validator node-module

what is a cron expression?

Cron is a time-based job scheduler in Unix operating systems. It helps to schedule repetitive jobs to run at fixed times, dates, or intervals.

Quartz

Before digging into the cron-expression-validator node-module it is good to know about quartz since the module supports to validate the Quartz engine generated cron expressions.

What is cron-expression-validator?

cron-expression-validator is a node-module that validates quartz cron expressions. You can find the cron-expression-validator node-module in here

Installation

You can simply install cron-expression-validator like any other node module. Just type,

npm install cron-expression-validator

What cron-expression-validator do?

  • It provides validation to a given cron expression — returns a boolean value
  • It provides validation and error messages if cron string is invalid — returns Object carrying boolean value and array

Usage

Once you install, include this node-module in your project

var cronValidator = require('cron-expression-validator');
var isValid = cronValidator.isValidCronExpression("* * * * * ? *"); // isValid -> true
if(cronValidator.isValidCronExpression("* * * * * ? *")) { 
// returns true
// Your code
}
if(cronValidator.isValidCronExpression("* * * * * * *")) {
// returns false
}
var validObj = cronValidator.isValidCronExpression(
"* * * * 25/2 ? *", {error: true});
var validObj = cronValidator.isValidCronExpression(
"* * * ? * * 123/555", {error: true});
var isValid = cronValidator.isValidCronExpression(
"0 0 12 1/2 * ? *", {error: false});

Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store