Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent render server from sleeping

Tags:

node.js

cron

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?

like image 523
Vic Tør Avatar asked Dec 07 '25 06:12

Vic Tør


2 Answers

Use https://console.cron-job.org/ and setup an HTTP call after every 14 minute.

like image 200
Mehta Avatar answered Dec 08 '25 19:12

Mehta


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();
 });
};
like image 39
Yusuf Avatar answered Dec 08 '25 18:12

Yusuf