forked from fsholehan/pingBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 846 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require("dotenv").config();
const express = require("express");
const axios = require("axios");
const app = express();
// Use environment variables
const PORT = process.env.PORT || 8000;
const apiUrl = process.env.API_URL;
// Example route
app.get("/", (req, res) => {
res.send("Hello World!");
});
// Function to send requests
function sendRequest() {
axios
.get(apiUrl)
.then((response) => {
console.log("Request successful:", response.data);
})
.catch((error) => {
console.error("Request failed:", error);
});
}
// Send a request immediately upon server start
sendRequest();
// Set interval to send request every 5 minutes (300000 ms)
setInterval(sendRequest, process.env.REQUEST_INTERVAL);
// Start the Express server
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});