A clean, minimalist weather application with Node.js/Express backend, Redis caching, and WeatherAPI.com integration.
- π€οΈ Real-time weather data from WeatherAPI.com
- π Automatic location detection using browser geolocation
- β‘ Redis caching with 15-minute TTL for improved performance
- π¨ Clean, minimalist UI inspired by modern weather apps
- π± Responsive design for mobile and desktop
- π Metric/Imperial unit conversion
- π Comprehensive weather stats (humidity, pressure, visibility, etc.)
- β° 24-hour hourly forecast
- π Sunrise/sunset times
- Node.js (v16 or higher)
- Redis server
- WeatherAPI.com API key (free tier available)
-
Clone or download the project files
-
Install dependencies
npm install
-
Set up Redis
Option A: Local Redis installation
# Ubuntu/Debian sudo apt-get install redis-server sudo systemctl start redis-server # macOS with Homebrew brew install redis brew services start redis # Windows - Download from https://redis.io/download
Option B: Docker
docker run -d -p 6379:6379 --name weather-redis redis:alpine
Option C: Cloud Redis (Redis Cloud, AWS ElastiCache, etc.)
-
Get WeatherAPI.com API Key
- Go to WeatherAPI.com
- Sign up for a free account
- Get your API key from the dashboard
-
Configure environment variables
cp .env.example .env
Edit
.envfile:PORT=3000 WEATHER_API_KEY=your_actual_api_key_here REDIS_HOST=localhost REDIS_PORT=6379 # REDIS_PASSWORD=your_redis_password (if needed) -
Place the HTML file
mkdir public # Move the weather app HTML file to public/index.html
-
Start the server
# Development mode with auto-restart npm run dev # Production mode npm start
-
Access the application
- Open your browser and go to
http://localhost:3000 - The app will automatically request your location
- Allow location access for best experience
- Open your browser and go to
GET /api/weather?lat={latitude}&lon={longitude}
Parameters:
lat: Latitude (-90 to 90)lon: Longitude (-180 to 180)
Response:
{
"location": {
"name": "New York",
"region": "New York",
"country": "United States of America",
"localtime": "2025-06-24 14:30"
},
"current": {
"temp_c": 27,
"temp_f": 80.6,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
"code": 1003
},
"wind_kph": 8.6,
"wind_mph": 5.3,
"humidity": 85,
"pressure_mb": 1010,
"feelslike_c": 27,
"vis_km": 10.0
},
"forecast": {
"sunrise": "06:06",
"sunset": "18:45",
"hourly": [...]
},
"cached": false,
"timestamp": "2025-06-24T14:30:00.000Z"
}GET /api/health
GET /api/cache/stats # View cache statistics
DELETE /api/cache/clear # Clear all cached weather data
weather-app/
βββ server.js # Main Express server
βββ package.json # Dependencies and scripts
βββ .env.example # Environment variables template
βββ .env # Your environment variables (create this)
βββ public/
β βββ index.html # Frontend HTML file
βββ README.md # This file
# Basic Redis setup
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_password
# Or use connection URL
REDIS_URL=redis://user:password@host:port- TTL: 15 minutes (900 seconds)
- Key format:
weather:{lat}:{lon}(coordinates rounded to 2 decimal places) - Storage: JSON stringified weather data
- Window: 15 minutes
- Max requests: 100 per IP
- Scope: All
/api/*endpoints
- Backend changes: Modify
server.js - Frontend changes: Edit
public/index.html - Dependencies: Update
package.json
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
WEATHER_API_KEY |
WeatherAPI.com API key | Required |
REDIS_HOST |
Redis server host | localhost |
REDIS_PORT |
Redis server port | 6379 |
REDIS_PASSWORD |
Redis password | None |
NODE_ENV |
Environment mode | development |
# Test weather endpoint
curl "http://localhost:3000/api/weather?lat=40.7128&lon=-74.0060"
# Check health
curl "http://localhost:3000/api/health"
# View cache stats
curl "http://localhost:3000/api/cache/stats"- Environment Variables: Set all required environment variables
- Redis: Use a managed Redis service (Redis Cloud, AWS ElastiCache)
- Process Management: Use PM2 or similar process manager
- Reverse Proxy: Use Nginx or similar for production
- HTTPS: Enable SSL/TLS certificates
- Monitoring: Add logging and monitoring solutions
{
"name": "weather-app",
"script": "server.js",
"instances": "max",
"env": {
"NODE_ENV": "production",
"PORT": 3000
}
}-
Redis Connection Error
- Verify Redis is running:
redis-cli ping - Check connection settings in
.env
- Verify Redis is running:
-
WeatherAPI.com Errors
- Verify API key is correct
- Check API quotas and limits
- Ensure coordinates are valid
-
Location Access Denied
- Browser must be accessed via HTTPS for geolocation (except localhost)
- User must grant location permission
-
Cache Not Working
- Check Redis connection
- Verify Redis has sufficient memory
- Check TTL settings
The application logs important events:
- Redis connection status
- Cache hits/misses
- API errors
- Server startup
MIT License - feel free to use this project for your own purposes.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request