1.5.1 • Published 5 years ago

pingmydyno v1.5.1

Weekly downloads
81
License
ISC
Repository
github
Last release
5 years ago

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

valuedefaultdescription
pingIntervalnumber (milliseconds)1200000interval between the next ping (max = 25mins)
maxRetrynumber2retry times when ping fail
onSuccessfunction( ) => nullcallback function called when a ping is successful
onFailurefunction( ) => nullcallback function called when maxRetry ping failed

Contributors

Thanks goes to these wonderful people (emoji key):

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

License

This project is license under MIT

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago