Skip to content

Latest commit

 

History

History
80 lines (61 loc) · 1.52 KB

README.md

File metadata and controls

80 lines (61 loc) · 1.52 KB

croninja logo

Introduction

A lightweight cron time parser

Code Samples

INPUT

const { Croninja } = require("croninja")

const cron = Croninja({
    second: 10,
    minute: 2,
    hour: 1,
    day: 0,
    month: 0,
  });

If current time is for e.g 2023 July 23 SUN 13:43:20, cronjob will run after 1 hour 2 minutes and 10 seconds (at 2023 July 23 SUN 14:45:40)

OUTPUT

40 45 14 23 7 * 

Example of use

const { Croninja } = require("croninja");
const cron = require("node-cron");

const crontime = Croninja({
  second: 10,
  minute: 1,
  hour: 0,
  day: 0,
  month: 0,
});

cron.schedule(
  crontime,
  async () => {
    try {
      console.log("This job ran after 1 minute and 10 seconds");
    } catch (e) {
      console.error(e);
    }
  },
  { scheduled: true }
);

List of parameters

Parameters Type Description
offsets object required (fields in object: second, minute, hour, day and month)
dayOfWeek string optional (value must be mon, tue, wed, thu, fri, sat or sun)

Installation

NPM:

npm install croninja

Yarn:

yarn add croninja