I got a node app hosted on a render server, and as it's under the free tier, it sleeps after 15m of inactivity, and I wrote a cron job using the node-cron package. if the app is asleep, the node-cron functions won't be active. is there any way to keep my render app awake?
I've used Heroku and Kaffeine (for keeping heroku apps awake)
are there any alternatives for Render?
Use https://console.cron-job.org/ and setup an HTTP call after every 14 minute.
You can create a lambda function and schedule it to trigger every N time and ping your server to keep it listening to incoming traffic, also you can see the log and monitor the of your function
const https = require('https');
exports.handler = async (event, context) => {
const url = 'https://yoursitehere.onrender.com';
return new Promise((resolve, reject) => {
const req = https.get(url, (res) => {
if (res.statusCode === 200) {
resolve({
statusCode: 200,
body: 'Server pinged successfully',
});
} else {
reject(
new Error(`Server ping failed with status code: ${res.statusCode}`)
);
}
});
req.on('error', (error) => {
reject(error);
});
req.end();
});
};
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