Not letting the App go down

It is possible to use the module without conflicting the port like this, please check documentation here: https://www.npmjs.com/package/node-keepalive

var express = require('express');
var app = express();

var keepAlive = require("node-keepalive");
keepAlive({}, app);

// ....... other express endpoints as per your project

var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

Yes, a service like https://uptimerobot.com/ is also a good option among other website monitors. Thanks for sharing that.

Anyways, I kept the node-keepalive module versatile and may work for something other than Glitch too. :wink: :grinning:


EDIT (A SOLUTION):

I am using the module in one of my Glitch projects and its working great. This solved the every 5 minutes sleep problem. But, I am sure that it will get shutdown in next 12 hours as mentioned here: Do Glitch projects shut down after every 12 hours?

So, I have installed the module on another Glitch project and using my other module (node-cron-link: https://www.npmjs.com/package/node-cron-link) to call one project with the other, so that if one goes down, the other one will bring it up. :smiley:

This is the code I am using in both projects:

var express = require('express');
var app = express();

var keepAlive = require("node-keepalive");
keepAlive({}, app);

// ....... other express endpoints as per your project

var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

var cronLink = require("node-cron-link");
cronLink("https://<other_project_name>.glitch.me/keepalive", {time: 2, kickStart: true});

Just start both projects one after another with a lag of 5-10 minutes.

Hope it helps someone. :+1:

3 Likes