I got a website hosted on a Heroku server (i'm a new to Heroku btw), and as it's under the free package, it sleeps after 30m of inactivity, and to put it in action again when a user hits it, it takes around 7 secs to npm run start
successfully.
I'm thinking of run a nodejs job or something that open the website every 29m so that the server never sleeps, initially, I got something like this:
(function wakeup() {
require('open')('https://mywebsite.herokuapp.com', (err) => {
if (err) throw err;
console.log('Woke up!');
setTimeout(wakeup, 1740000); //29m
});
})()
N.B.: That just opens it in a browser, but not handling closing it.
Kaffeine pings your Heroku app every 30 minutes so it will never go to sleep* (read more)
If an app has a free web dyno, and that dyno receives no web traffic in a 30-minute period, it will sleep. In addition to the web dyno sleeping, the worker dyno (if present) will also sleep. Free web dynos do not consume free dyno hours while sleeping.
You have two options to keep your app awake: You can leave your Heroku account unverified (i.e. without a credit card linked) and have enough free hours for your app to run 18 hours per day.
Starting today, Heroku accounts have an account-based pool of free dyno hours for use on free apps. This replaces the 18 hours a day limit on free apps, allowing a free app to run 24/7 if needed. New accounts receive 550 free dyno hours and you can verify your identity with a credit card for an additional 450 hours.
It is perfectly legal to keep your free dyno awake for as long as you want, by any means at your disposal. Just note that your monthly allocation of free dyno hours is limited. If you verified your Heroku account with a credit card, you have 1000 free dyno hours per month, which is more than enough to keep a single free web dyno up "forever" without sleeping at all. A very easy way to do that is simply to configure a New Relic add-on for your app (using the free New Relic plan), which you can easily configure to ping your Heroku app periodically. For additional methods to prevent your Heroku app from idling, see here.
Try Kaffeine it will prevent your app from sleeping. Heroku obliges free apps to sleep 6 hours. Kaffeine gives you the possibility to choose when your app sleeps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With