Skip to content

An advanced weather app with a simple authentication system , go check it out πŸ”₯πŸ”₯πŸ‘Œ

Notifications You must be signed in to change notification settings

maasch/Weather-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Weather App

A full-stack weather application with user authentication, featuring real-time weather data, 5-day forecasts, and a modern responsive UI with dark/light mode support.

Features

  • 🌀️ Real-time Weather Data: Get current weather conditions for any city worldwide
  • πŸ“… 5-Day Forecast: View detailed weather forecasts for the next 5 days
  • πŸ” User Authentication: Secure registration and login system with session management
  • 🎨 Dark/Light Mode: Toggle between dark and light themes with persistent preferences
  • πŸ” City Search: Search for cities with autocomplete suggestions
  • πŸ“Š Weather Metrics: Display temperature, humidity, wind speed, and wave height (coastal areas)
  • πŸ–ΌοΈ City Images: Beautiful city images from Unsplash API
  • πŸ“± Responsive Design: Mobile-friendly interface that works on all devices
  • 🌊 Marine Data: Wave information for coastal locations

Tech Stack

Frontend

  • HTML5/CSS3: Modern semantic markup and styling
  • Vanilla JavaScript (ES6+): No framework dependencies, pure JavaScript
  • Day.js: Lightweight date manipulation library

Backend

  • Node.js: Server runtime environment
  • Express.js: Web application framework
  • MySQL: Relational database for user data
  • bcrypt: Password hashing for security
  • express-session: Session management
  • express-mysql-session: MySQL session store

APIs Used

  • OpenWeatherMap API: Weather data and forecasts
  • Unsplash API: City images
  • Open-Meteo API: Marine/wave data

Project Structure

Weather App/
β”œβ”€β”€ Server/
β”‚   β”œβ”€β”€ server.js           # Express server and API endpoints
β”‚   β”œβ”€β”€ package.json        # Node.js dependencies
β”‚   └── node_modules/       # Dependencies
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ script.js          # Main weather functionality
β”‚   β”œβ”€β”€ auth.js            # Authentication handlers
β”‚   β”œβ”€β”€ user-auth.js       # Authenticated user page logic
β”‚   β”œβ”€β”€ modes.js           # Theme mode switching
β”‚   └── meh.js             # Utility functions
β”œβ”€β”€ styles/
β”‚   β”œβ”€β”€ all.css            # Global styles
β”‚   β”œβ”€β”€ main.css           # Main page styles
β”‚   β”œβ”€β”€ header.css         # Header component styles
β”‚   β”œβ”€β”€ auth.css           # Authentication page styles
β”‚   β”œβ”€β”€ 5-days.css         # Forecast section styles
β”‚   β”œβ”€β”€ modes.css          # Theme mode styles
β”‚   β”œβ”€β”€ landing.css        # Landing page styles
β”‚   └── responsivity.css   # Responsive design styles
β”œβ”€β”€ images/
β”‚   └── profil.png         # Profile images
β”œβ”€β”€ index.html             # Public landing page
β”œβ”€β”€ auth.html              # Login/Register page
β”œβ”€β”€ user-auth.html         # Authenticated user dashboard
└── README.md              # Project documentation

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14 or higher)
  • MySQL (v5.7 or higher)
  • pnpm (v10.17.0 or compatible package manager)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd "Weather App"
  2. Install dependencies

    cd Server
    pnpm install
  3. Set up the MySQL database

    Create a database named weatherapp:

    CREATE DATABASE weatherapp;

    The application will automatically create the users table using express-mysql-session. However, you can manually create it:

    USE weatherapp;
    
    CREATE TABLE users (
      id INT AUTO_INCREMENT PRIMARY KEY,
      name VARCHAR(255) NOT NULL,
      email VARCHAR(255) UNIQUE NOT NULL,
      password VARCHAR(255) NOT NULL,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
  4. Configure the server

    Edit Server/server.js and update the MySQL connection details:

    const db = mysql.createConnection({
      user: 'root',        // Your MySQL username
      host: 'localhost',
      password: '',        // Your MySQL password
      database: 'weatherapp'
    });
  5. Get API Keys

    You'll need API keys for:

    Update the API keys in scripts/script.js:

    const accessKey = 'YOUR_UNSPLASH_ACCESS_KEY';
    const apiKey = 'YOUR_OPENWEATHERMAP_API_KEY';

Running the Application

  1. Start the MySQL service

    • Make sure MySQL is running on your machine
  2. Start the server

    cd Server
    pnpm start

    Or for development with auto-reload:

    pnpm dev
  3. Open your browser

    Navigate to http://localhost:3000

Usage

Public Access

  • Visit the homepage to search and view weather for any city
  • View current weather conditions and 5-day forecasts
  • No authentication required for basic weather viewing

User Account

  1. Click "Sign Up" or "Login" in the header
  2. Register with a username, email, and password
  3. After login, you'll be redirected to the authenticated dashboard
  4. Access your profile settings via the profile icon
  5. Toggle between dark/light mode
  6. Logout when finished

API Endpoints

Authentication

  • POST /auth/register - Register a new user
  • POST /auth/login - Login user
  • GET /auth/logout - Logout user
  • GET /api/session - Check current session

Pages

  • GET / - Public landing page
  • GET /auth - Authentication page
  • GET /user-auth.html - Authenticated user dashboard (requires login)

Configuration

Session Configuration

The session is configured with:

  • Cookie name: UserId
  • Max age: 24 hours
  • Storage: MySQL database

Security Notes

⚠️ For Production Use:

  • Change the session secret in server.js (currently '369369')
  • Set secure: true in cookie options when using HTTPS
  • Implement environment variables for sensitive data (API keys, database credentials)
  • Use .env file for configuration (recommended)

Features in Detail

Weather Display

  • Current temperature with feels-like temperature
  • Humidity percentage
  • Wind speed (km/h)
  • Wave height for coastal areas (meters)
  • Weather condition descriptions
  • Dynamic weather icons based on conditions

5-Day Forecast

  • Daily temperature
  • Humidity and wind speed for each day
  • Weather icons matching forecast conditions
  • Formatted dates with day names

City Search

  • Real-time autocomplete suggestions
  • Support for major cities worldwide
  • Custom city list with Moroccan cities included
  • Search via input or Enter key

Theme Management

  • Light and dark mode support
  • Theme preference saved in localStorage
  • Smooth theme transitions
  • Consistent theming across all components

Development

Project Architecture

  • Frontend: Client-side JavaScript with ES6 modules
  • Backend: RESTful API with Express.js
  • Database: MySQL for user management and sessions
  • Styling: Modular CSS architecture

Code Style

  • ES6+ JavaScript features
  • Modular script organization
  • Semantic HTML structure
  • Responsive CSS with mobile-first approach

Troubleshooting

Common Issues

  1. Database Connection Error

    • Verify MySQL is running
    • Check database credentials in server.js
    • Ensure database weatherapp exists
  2. API Errors

    • Verify API keys are correct
    • Check API rate limits (free tier has limits)
    • Ensure internet connection is active
  3. Session Issues

    • Clear browser cookies
    • Check MySQL session store is working
    • Verify session middleware is configured correctly
  4. Port Already in Use

    • Change port in server.js (default: 3000)
    • Or stop the process using port 3000

Contributing

This project is open for contributions. When contributing:

  1. Follow the existing code style
  2. Test your changes thoroughly
  3. Update documentation as needed

License

ISC License

Author

4YA Products Β© 2025

Acknowledgments

About

An advanced weather app with a simple authentication system , go check it out πŸ”₯πŸ”₯πŸ‘Œ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published