Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/luqmanoop/pingmydyno

Keep Heroku dynos awake forever ☕️
https://github.com/luqmanoop/pingmydyno

dyno heroku nodejs ping typescript

Last synced: 3 months ago
JSON representation

Keep Heroku dynos awake forever ☕️

Awesome Lists containing this project

README

        



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

```bash
npm install pingmydyno

# or using yarn

yarn add pingmydyno
```

## Usage

With Express.js (ES6 module)

```javascript
...
import express from 'express';
import pingmydyno from 'pingmydyno';

const app = express();

...

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

```

With Hapi.js (commonJS)

```javascript
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

```javascript
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](https://allcontributors.org/docs/en/emoji-key)):

Kizito Akhilome
Kizito Akhilome

💻Luqman Olushi O.
Luqman Olushi O.

🐛 💻 📖 🚧

This project follows the
[all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!

## License

This project is license under
[MIT](https://github.com/codeshifu/pingmydyno/blob/master/LICENSE)