npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hapi-cron-job

v2.0.1

Published

Cron/Schedule jobs for Hapi framework

Readme

hapi-cron-job

cron_jobs

Overview

hapi-cron-job, is a plugin for hapi that will allows you to execute cron job at a specified time (eg: every 2 hour, at 8:00 pm, every monday at 11:00 am, every first day of the month).

Installation

Using npm:

npm install hapi-cron-job

How to:

See pratical example

var displayTime = function(){
    var ymd = new Date().toISOString().slice(0,new Date().toISOString().indexOf("T"));
    var hms = new Date().toISOString().substr(11, 8);
    console.log(ymd+" "+hms);
};
var callback = function(enabledJobs){
    //Do something with enabledJobs
}
var enabledCallback = function(job, scheduleParsed){
    //Do something with job and scheduleParsed
}
Server.register({
    register:require('hapi-cron-job'),
    options:{
        jobs:[
             {
                name:"diplay time",
                enabled:true,
                enabledCallback:enabledCallback,//Executed at end of import of the job, just before immediate Callback
                immediate:true,//Will execute function on starting
                schedule:"every 1 s",
                execute:displayTime,
                environments:['development','staging']//using env (process.env.NODE_ENV)
             }
        ],
        callback:callback//Executed at end of process and return enabledJobs
    }
},function(err){
     if(err){throw err;}
 });

Options

  • jobs : An array of jobs
    • name: (String) Name of your cron job
    • enabled: (Bool) Do we want to enable our cron job
    • enabledCallback: (Function, optional) Function to execute at end of import of the job, before call (if immediate is true)
    • schedule: (String) See allowed Schedule, example or use.
    • execute: (Function) Function to execute at schedule
    • immediate: (Bool, optional, default:false)
    • environments:(Array(String), optional) Use process.env.NODE_ENV to set your environments. If no environments set consider as active.
  • localTime: (default: true, optional), If false, use GMT Zone(UTC Time) instead of local server time (local Zone)
  • callback: (optional), A callback function that will be executed at the end of the import process, {return: enabledJobs(Array)}

Allowed schedule

You can specify any schedule format that look like :

  • at : can be
    • at 01:00 pm, 01:00 am, 1:00am etc... (will be called daily at specified time).
    • at 15:00
  • every : can be :
    • every 1 hour, every 1 hours, every 1 h. (Works with seconds, minutes, hours, days)
    • every plain hour, every plain minutes. (Works with min, hours)

Mind that every X PERIOD, is absolute, if you started your server at 10:44 pm and set to every 1 h, it will be executed at 11:44pm, 0:44am and so on...
You can have your cron executed at the next plain hour and every next hour then.

Use every plain hour for that. (eg:If started at 3:46, next exec will be 4:00 then 5:00...)
Same can be done with minutes with every plain minute (eg: Started at 3:46, next exec will be 3:50,4:00,..)

Definitions

  • Period : s, m, h, d, seconds, second, ....
  • Number : 1, 2, ...
  • Times : 8:00 pm, 08:00 pm
  • Ordinal Number : first, second, thenth,...

Next :

  • Handle leap year
  • Handle daylight saving time (so, notice that we actually don't handle this)
  • Parse : after NUMBER PERIOD
  • Parse : every DAYS at TIMES
  • Parse : every PERIOD on the ORDINALNUMBER PERIOD of the PERIOD eg : every minutes on the first day of the month
  • Parse : every ORDINALNUMBER PERIOD of PERIOD
    eg: every first day of the month
  • ~~Handle 24-hour times (at 01:00 will be 01:00am, at 16:00 will be 4:00pm) : ~~ DONE
  • Handle days
  • handle months
  • Handle years

About you

If this can help even one person, I would be hapi enough (see what I did here ? :D).
I will work on that project till I will be confident enought that it will answer perfectly to the need to at least one person.
If you are that person, please, do not hesitate to :

  • submit any issues,
  • raises any questions,
  • submit any PR
  • or anything else (critism, stuff that need to be improved).

You could also drop me a word on twitter : @obusco.

I would like to have any feedback that you use it, may be even for what and how I could help improving this package to fit your needs.

About stuff

  • Limitations :
  1. About max_time : For now (till I get smart and find a way to handle that), you can't plan something over 68 years.
    I was stuck at 24 days initially (INT 32 limit on setTimeout), but I excess that limit by forcing me to work in seconds instead of milliseconds. I will, probably, I think, may be, move that limit away.
    But for now, if you want to code an IA that plan to nuke the world in 69 years. Mind about setting up to 67/68 years instead.

Versioning

Releases will be numbered with the following format (semver):

<major>.<minor>.<patch>

The reason we doing that, is that, far from marketing or stuff. You will know easily if a breaking change occurs by just looking the first number. Mind that some major version (breaking changes) can be absolutely necessary (bugfix). But at least it won't break your code

Contributors

I want to take time to thank :

Much love to you ! <3

Inspired by