Weather_Website

WeatherNow - Production Ready Weather Application

A modern, production-ready weather application built with Node.js, Express, and vanilla JavaScript.

๐Ÿš€ Features

Backend

Frontend

๐Ÿ“ Project Structure

weather-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

๐Ÿ› ๏ธ Setup

1. Install Dependencies

npm install

2. Configure Environment

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

3. Run the Server

# Development mode
npm run dev

# Production mode
npm start

๐Ÿ“ก API Endpoints

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

๐Ÿ”’ Security Features

๐Ÿ“Š Standardized API Response Format

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"
}

๐ŸŒ Deployment (Render)

  1. Push code to GitHub
  2. Create new Web Service on Render
  3. Connect your repository
  4. Add environment variables:
    • OPENWEATHER_API_KEY
    • CORS_ALLOWED_ORIGINS (include your Render URL)
    • NODE_ENV=production
  5. Deploy!

๐Ÿงช Testing

Test the health endpoint:

curl http://localhost:3001/api/health

Test weather API:

curl "http://localhost:3001/api/weather?lat=51.5074&lon=-0.1278"

๐Ÿ“ Changelog

v2.0.0 - Production Ready

Removed:

Added:

Improved:

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ“ง Support

For issues and questions, please open an issue on GitHub.