const http = require(‘http’);
const express = require(‘express’);
const app = express();
app.get("/", (request, response) => {
console.log(Date.now() + " Ping Received");
response.sendStatus(200);
});
app.listen(process.env.PORT);
setInterval(() => {
http.get(http://${process.env.PROJECT_DOMAIN}.glitch.me/
);
}, 280000);
I’m currently using this code (found on the usage section) in my node project to keep my bot online
const express = require('express');
const keepalive = require('express-glitch-keepalive');
const app = express();
app.use(keepalive);
app.get('/', (req, res) => {
res.json('This bot should be online! Uptimerobot will keep it alive');
});
app.get("/", (request, response) => {
response.sendStatus(200);
});
app.listen(process.env.PORT);
Then I use uptimerobot to send a request to it.
It uses the module https://www.npmjs.com/package/express-glitch-keepalive
We don’t recommend you use setInterval to keep a bot alive. It’s more reliable to define a route and use UptimeRobot. Note that you don’t have to use both Uptime Robot and the keepalive module together. It’s enough to just use Uptimerobot.
The method you mentioned doesn’t work for me. It’s just an endless loading screen when you try and view the page. Which doesn’t work in uptimerobot. I’m hosting a bot, not a website along with it so that’s why it’s just an endless loading screen. Besides it doesn’t seem to keep it online either, with just using uptimerobot, just shuts off after 5 minutes as normal, cause of it endless loading. The script I used creates the 200 status page.
You seem to have ignored the bit where I mention defining a route, which would stop the endless loading and make it work. The following is all you need with UptimeRobot:
const express = require('express');
const app = express();
app.get("/", (request, response) => {
response.sendStatus(200);
});
app.listen(process.env.PORT);
So do you need to install it via node? There site is currently down so
This didn’t work for me, I copied your code, and didn’t catch any errors
And Gareth’s method too? His method works as well.
At first I didn’t get what he was saying, but I got it to work after following another guide