UptimePulse is a service that monitors the availability of websites by periodically sending HTTP requests and logging their uptime.
# Initialize project
npm init -y
# Install dependencies
npm install express pg node-cron dotenv axios cors
To run this application:
npm start
/uptimepulse-backend
│── server.js
│── config/
│ ├── db.js
│── routes/
│ ├── monitorRoutes.js
│── controllers/
│ ├── monitorController.js
│── models/
│ ├── monitorModel.js
│── utils/
│ ├── uptimeChecker.js
│── .env
│── package.json
CREATE TABLE monitors (
id SERIAL PRIMARY KEY,
url TEXT NOT NULL,
interval INTEGER DEFAULT 5, -- Check every X minutes
last_status INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE logs (
id SERIAL PRIMARY KEY,
monitor_id INTEGER REFERENCES monitors(id) ON DELETE CASCADE,
status_code INTEGER,
response_time INTEGER,
checked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
POST /monitor
{
"url": "https://example.com",
"interval": 5
}
{
"message": "Monitor added successfully",
"monitor": { "id": 1, "url": "https://example.com", "interval": 5 }
}
GET /monitors
[
{ "id": 1, "url": "https://example.com", "interval": 5, "last_status": 200 }
]
DELETE /monitor/:id
{
"message": "Monitor deleted successfully"
}
- A
node-cron
job runs every X minutes (as per the monitor settings). - It sends an HTTP GET request using
axios
. - Logs response status and time in the
logs
table. - If the site is down, retries the check and sends an alert if still down.
- Push your code to GitHub.
- Create a new Web Service on Render.com.
- Connect your GitHub repository.
- Add environment variables:
DATABASE_URL
(PostgreSQL connection string)PORT=5000
- Deploy and test using Postman or frontend.
- User authentication (optional).
- Webhooks for real-time notifications.
- Dashboard UI to display uptime statistics.
This document serves as a guide to setting up and running the UptimePulse backend. 🚀