A university web programming project built with Node.js, Express, PostgreSQL, and vanilla JavaScript + Chart.js.
webbbbbb/
├── backend/
│ ├── config/db.js # DB connection pool
│ ├── controllers/ # Business logic
│ ├── middleware/ # JWT auth & error handling
│ ├── models/ # SQL query functions
│ ├── routes/ # Express routers
│ ├── utils/ # Helpers (API key gen)
│ ├── schema.sql # DB schema & indexes
│ ├── app.js # Express setup
│ └── server.js # Entry point
├── frontend/
│ ├── index.html # Login page
│ ├── register.html
│ ├── dashboard.html # Overview + charts
│ ├── devices.html # Device CRUD
│ ├── device-detail.html # Per-device chart
│ ├── alerts.html # Alert notifications
│ ├── css/style.css
│ └── js/ # Page-specific JS
├── simulator.js # Fake IoT device sender
└── package.json
npm installCopy .env.example to .env and fill in your values:
cp backend/.env.example backend/.envEdit backend/.env:
PORT=3000
DB_HOST=localhost
DB_PORT=3306
DB_NAME=iot_monitoring
DB_USER=root
DB_PASSWORD=yourpassword
JWT_SECRET=your_super_secret_jwt_key_here
mysql -u root -p -e "CREATE DATABASE iot_monitoring CHARACTER SET utf8mb4;"
mysql -u root -p iot_monitoring < backend/schema.sql# Development (with auto-reload)
npm run dev
# Production
npm startOpen your browser and navigate to:
http://localhost:3000
If you don't have a physical IoT device, use the simulator:
# First, create a device via the UI and copy its API key
# Then run:
node simulator.js <YOUR_API_KEY>
# Example:
node simulator.js abc123def456...The simulator sends temperature + humidity readings every 5 seconds.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register a new user |
| POST | /api/auth/login |
Login, returns JWT token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/devices |
List all your devices |
| POST | /api/devices |
Add a new device |
| GET | /api/devices/:id |
Get device details |
| PUT | /api/devices/:id |
Update device |
| DELETE | /api/devices/:id |
Delete device |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/sensor/data |
API Key header | Submit sensor reading |
| GET | /api/sensor/data/:deviceId |
JWT | Get readings |
| GET | /api/sensor/stats/:deviceId |
JWT | Get statistics |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/alerts |
Get all alerts |
| PATCH | /api/alerts/:id/read |
Mark as read |
| DELETE | /api/alerts/:id |
Delete alert |
- users — Registered users with hashed passwords
- devices — IoT devices with unique API keys and alert thresholds
- sensor_data — Time-series temperature & humidity readings (indexed)
- alerts — Auto-generated alerts when thresholds are exceeded
- Backend: Node.js, Express.js, JWT, bcryptjs
- Database: MySQL (with mysql2 driver)
- Frontend: HTML5, CSS3, Bootstrap 5, Vanilla JS, Chart.js
- Architecture: MVC pattern, RESTful API