Skip to content

luqmanoop/pingmydyno

Repository files navigation

pingmydyno

Keep Heroku dynos awake forever ☕️

License: MIT PRs Welcome GitHub contributors

Why?

Heroku (free) dynos are great for hosting apps and showing them off to your boss/friends or potential employer. The downside, however, is that your app will fall asleep 😴 if it doesn't receive any web traffic within a 30-minute window.

pingmydyno solves this by pinging your server periodically so it never falls asleep.

Features

  • Forever dyno pings
  • Automatically retry ping on failure

Installation

npm install pingmydyno

# or using yarn

yarn add pingmydyno

Usage

With Express.js (ES6 module)

...
import express from 'express';
import pingmydyno from 'pingmydyno';

const app = express();

...

app.listen(PORT, () => {
    pingmydyno('https://myapp.herokuapp.com');
});

With Hapi.js (commonJS)

const Hapi = require('hapi');
const pingmydyno = require('pingmydyno');

const server = Hapi.server({ port, host });

async () => {
  await server.start();
  pingmydyno('https://myapp.herokuapp.com');
};

With Koa.js

const Koa = require('koa');
const pingmydyno = require('pingmydyno');

const app = new Koa();
const url = process.env.APP_URL;

...

app.listen(3000).on('listening', () => {
    pingmydyno(url, {
        pingInterval: 60 * 15 * 1000, // ping every 15mins
        onFailure() {
            // logger
        }
    })
})

APIs

pingmydyno(url, [Config])

url

Type: string

Required: yes

Config

Type: Object

Required: no

value default description
pingInterval number (milliseconds) 1200000 interval between the next ping (max = 25mins)
maxRetry number 2 retry times when ping fail
onSuccess function ( ) => null callback function called when a ping is successful
onFailure function ( ) => null callback function called when maxRetry ping failed

Contributors

Thanks goes to these wonderful people (emoji key):

Kizito Akhilome
Kizito Akhilome

💻
Luqman Olushi O.
Luqman Olushi O.

🐛 💻 📖 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is license under MIT