A modern, production-ready weather application built with Node.js, Express, and vanilla JavaScript.
/api/health endpoint for monitoringweather-website/
โโโ server/
โ โโโ proxy-server.js # Main server file (only server file)
โโโ public/
โ โโโ index.html # Frontend HTML
โ โโโ script.js # Frontend JavaScript
โ โโโ styles.css # Frontend CSS
โโโ .env.example # Environment variables template
โโโ package.json # Dependencies
โโโ README.md # This file
npm install
Copy .env.example to .env and add your API key:
# Get your API key from: https://home.openweathermap.org/users/sign_up
OPENWEATHER_API_KEY=your_api_key_here
# Server port (optional, defaults to 3001)
PORT=3001
# Node environment
NODE_ENV=development
# CORS Allowed Origins (comma-separated)
CORS_ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com
# Development mode
npm run dev
# Production mode
npm start
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Frontend application |
| GET | /api/health |
Server health check |
| GET | /api/weather?lat=&lon= |
Current weather |
| GET | /api/geo?q= |
Geocoding (city search) |
| GET | /api/reverse-geo?lat=&lon= |
Reverse geocoding |
| GET | /api/air-pollution?lat=&lon= |
Air quality index |
| GET | /api/alerts?lat=&lon= |
Weather alerts |
| GET | /api/onecall?lat=&lon= |
Forecast data |
| GET | /api/cache/stats |
Cache statistics |
| POST | /api/cache/clear |
Clear cache |
All endpoints return consistent JSON:
{
"success": true,
"data": { ... },
"error": null,
"message": "Optional message"
}
Error response:
{
"success": false,
"data": null,
"error": "ERROR_CODE",
"message": "Human-readable error message"
}
OPENWEATHER_API_KEYCORS_ALLOWED_ORIGINS (include your Render URL)NODE_ENV=productionTest the health endpoint:
curl http://localhost:3001/api/health
Test weather API:
curl "http://localhost:3001/api/weather?lat=51.5074&lon=-0.1278"
Removed:
Added:
Improved:
MIT License - see LICENSE file for details.
For issues and questions, please open an issue on GitHub.