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.
- π€οΈ 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
- HTML5/CSS3: Modern semantic markup and styling
- Vanilla JavaScript (ES6+): No framework dependencies, pure JavaScript
- Day.js: Lightweight date manipulation library
- 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
- OpenWeatherMap API: Weather data and forecasts
- Unsplash API: City images
- Open-Meteo API: Marine/wave data
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
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)
-
Clone the repository
git clone <repository-url> cd "Weather App"
-
Install dependencies
cd Server pnpm install -
Set up the MySQL database
Create a database named
weatherapp:CREATE DATABASE weatherapp;
The application will automatically create the
userstable 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 );
-
Configure the server
Edit
Server/server.jsand update the MySQL connection details:const db = mysql.createConnection({ user: 'root', // Your MySQL username host: 'localhost', password: '', // Your MySQL password database: 'weatherapp' });
-
Get API Keys
You'll need API keys for:
- OpenWeatherMap: Sign up at openweathermap.org and get your free API key
- Unsplash: Sign up at unsplash.com/developers for a free API key
Update the API keys in
scripts/script.js:const accessKey = 'YOUR_UNSPLASH_ACCESS_KEY'; const apiKey = 'YOUR_OPENWEATHERMAP_API_KEY';
-
Start the MySQL service
- Make sure MySQL is running on your machine
-
Start the server
cd Server pnpm startOr for development with auto-reload:
pnpm dev
-
Open your browser
Navigate to
http://localhost:3000
- 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
- Click "Sign Up" or "Login" in the header
- Register with a username, email, and password
- After login, you'll be redirected to the authenticated dashboard
- Access your profile settings via the profile icon
- Toggle between dark/light mode
- Logout when finished
POST /auth/register- Register a new userPOST /auth/login- Login userGET /auth/logout- Logout userGET /api/session- Check current session
GET /- Public landing pageGET /auth- Authentication pageGET /user-auth.html- Authenticated user dashboard (requires login)
The session is configured with:
- Cookie name:
UserId - Max age: 24 hours
- Storage: MySQL database
- Change the session secret in
server.js(currently'369369') - Set
secure: truein cookie options when using HTTPS - Implement environment variables for sensitive data (API keys, database credentials)
- Use
.envfile for configuration (recommended)
- 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
- Daily temperature
- Humidity and wind speed for each day
- Weather icons matching forecast conditions
- Formatted dates with day names
- Real-time autocomplete suggestions
- Support for major cities worldwide
- Custom city list with Moroccan cities included
- Search via input or Enter key
- Light and dark mode support
- Theme preference saved in localStorage
- Smooth theme transitions
- Consistent theming across all components
- Frontend: Client-side JavaScript with ES6 modules
- Backend: RESTful API with Express.js
- Database: MySQL for user management and sessions
- Styling: Modular CSS architecture
- ES6+ JavaScript features
- Modular script organization
- Semantic HTML structure
- Responsive CSS with mobile-first approach
-
Database Connection Error
- Verify MySQL is running
- Check database credentials in
server.js - Ensure database
weatherappexists
-
API Errors
- Verify API keys are correct
- Check API rate limits (free tier has limits)
- Ensure internet connection is active
-
Session Issues
- Clear browser cookies
- Check MySQL session store is working
- Verify session middleware is configured correctly
-
Port Already in Use
- Change port in
server.js(default: 3000) - Or stop the process using port 3000
- Change port in
This project is open for contributions. When contributing:
- Follow the existing code style
- Test your changes thoroughly
- Update documentation as needed
ISC License
4YA Products Β© 2025
- Weather data provided by OpenWeatherMap
- City images from Unsplash
- Marine data from Open-Meteo