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 🙏

© 2024 – Pkg Stats / Ryan Hefner

periodic-ping

v2.0.0

Published

Stand-alone node task that sends out periodic HTTP requests to keep servers awake.

Downloads

11

Readme

NPM

Intro

Periodic Ping

Stand-alone node task that sends out periodic HTTP requests to keep servers awake.

  • Sets up a setInterval task that will 'ping' a server (send an HTTP GET request) every so often
    • Original purpose: to keep Heroku dynos alive during certain times of day, when they might otherwise scale down
    • (Future version may allow sending pings to other URLs for various reasons)
  • Takes several parameters to let you customize how it behaves
    • Set the wakeTime, sleepTime, etc (i.e. define a "time-window" within which the pings will be actually sent)
      • While the task will still continue to loop at the set interval, as long as it is OUTSIDE of the sleep/wake threshold, nothing will happen.
    • Useful for having the server get awoken only during a PART of every day, instead of around-the-clock, to better conserve resources, etc.
  • Or simply pass an appName, to have the process automatically ping the Heroku app by that name, every 5 minutes.

Alternatives

Usage in your .js code

Special notes:

  • App will assume standard herokuapp.com naming convention (i.e. 'abc123dummyHerokuDomainName' === http://abc123dummyHerokuDomainName.herokuapp.com)
  • App will assume your Heroku server has an HTTP handler at /periodicping, and dispatch the HTTP GET request to that endpoint (this could perhaps cause 404s or other errors, if you did not create this URL).

Import package as per usual conventions:

import {ping} from 'periodic-ping';

Pre-ES6 syntax will still work:

var ping = require('periodic-ping').ping;

Base case

Call with only an appName parameter supplied:

ping({appName: "abc123dummyHerokuDomainName"});// will take the default 'frequency' variable of 300000 (every 5 minutes)
...
ping({appName: "abc123dummyHerokuDomainName", frequency: 60000});// will override the default and use the specified frequency

Advanced case

Define a config object...

const myPingConfig = {
  appName: "abc123dummyHerokuDomainName",
  wakeTime: 9,
  wakeAm: true,
  sleepTime: 5,
  sleepAm: false
};

...supply the config object when calling the package function, to enable the "time-window" feature a.k.a. set wake/sleep thresholds, between which are the only times pings will be sent out:

ping(myPingConfig); // will only ping server between 9am and 5pm

Special notes for advanced case:

  • wakeTime and sleepTime may be decimal or whole number form, but must be JavaScript numbers greater than 0 and less-than or equal to 12, representing a time along a 12-hour clock.
  • A.M. / P.M. options are passed in via wakeAm and sleepAm respectively, where true will correspond to A.M., and false will convert the supplied number into it's respective P.M. form