A modern, real-time weather application built with Next.js and React. Get instant weather updates, hourly forecasts, and 5-day predictions for any city worldwide.
Developer: Zain Aftab
- Real-time Weather Data: Current temperature, humidity, wind speed, and atmospheric pressure
- City Search: Search for weather in any city worldwide with instant results
- Geolocation Support: Automatically detect and display weather for your current location
- Hourly Forecast: View weather predictions for the next 24 hours
- 5-Day Forecast: Plan ahead with a comprehensive 5-day weather forecast
- Temperature Unit Toggle: Switch between Celsius and Fahrenheit with one click
- Sunrise & Sunset Times: Know exactly when the sun rises and sets
- Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
- Dark Mode Support: Beautiful dark mode for comfortable viewing
- Last Updated Timestamp: See when the weather data was last refreshed
- Error Handling: Clear error messages and retry functionality
- Frontend Framework: Next.js 16 with React 19
- Styling: Tailwind CSS v4
- Icons: Lucide React
- API: OpenWeatherMap API
- Language: TypeScript
- Components: shadcn/ui
- Node.js 18+ installed
- An OpenWeatherMap API key (included in this project)
- Clone or download this project
- Install dependencies using the shadcn CLI:
npx shadcn-cli@latest init
- Run the development server:
npm run dev
- Open http://localhost:3000 in your browser
The app uses the following API key (already configured):
API_KEY:fb8de5c7d63da57183ef875cd7a1103e(OpenWeatherMap)
- Enter a city name in the search bar at the top
- Press Enter or click the search button
- Weather data loads instantly
- Click the "My Location" button in the top-right
- Allow location access when prompted
- Weather for your current location displays automatically
- Click the temperature unit button (°C or °F) in the top-right
- All temperatures instantly convert to your preferred unit
- Hourly: See detailed weather for the next 24 hours
- 5-Day: Get a daily forecast for the next 5 days
├── app/
│ ├── page.tsx # Main weather app page
│ ├── layout.tsx # Root layout
│ ├── globals.css # Global styles
│ └── loading.tsx # Loading state
├── components/
│ ├── current-weather.tsx # Current weather display
│ ├── search-bar.tsx # City search input
│ ├── forecast-card.tsx # Individual forecast card
│ ├── hourly-forecast.tsx # Hourly forecast display
│ ├── loading-spinner.tsx # Loading spinner
│ └── ui/ # shadcn/ui components
└── README.md # This file
Displays real-time weather including:
- Current temperature and "feels like" temperature
- Weather description with icon
- Humidity percentage
- Wind speed
- Atmospheric pressure
- Visibility distance
- Sunrise and sunset times
- Last updated timestamp
Shows the next 24 hours with:
- Time-based weather predictions
- Temperature and conditions
- Hourly weather icons
- Horizontally scrollable for easy browsing
5 individual cards showing:
- Daily date
- Maximum and minimum temperatures
- Weather conditions and icons
- Humidity levels
This app uses the OpenWeatherMap API with the following endpoints:
- Current Weather:
https://api.openweathermap.org/data/2.5/weather - Forecast Data:
https://api.openweathermap.org/data/2.5/forecast
Both endpoints support queries by:
- City name:
?q=London - Coordinates:
?lat=51.5074&lon=-0.1278 - Units:
metric(Celsius) orimperial(Fahrenheit)
The app includes comprehensive error handling for:
- City not found errors
- Network failures
- Geolocation permission denied
- Location unavailable
- API request timeouts
- Invalid responses
All errors display user-friendly messages with a "Retry" button.
- Efficient state management with React hooks
- Data validation before rendering
- Proper error boundaries
- Responsive images and icons
- Optimized CSS with Tailwind utility classes
- Fast API calls with proper error handling
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
- Mobile browsers (iOS Safari, Chrome Mobile)
Potential features for future versions:
- Weather alerts and warnings
- Multiple location tracking
- Weather history and trends
- Air quality index (AQI)
- UV index information
- Extended 10-day forecast
- Precipitation probability
- Wind direction visualization
- Weather maps integration
- Check spelling of the city name
- Try using the city with country code (e.g., "London, UK")
- Ensure location permission is granted in browser settings
- Some browsers require HTTPS for geolocation
- Check if your device has location services enabled
- Click the Retry button in the error message
- Try refreshing the page
- Check your internet connection
This project is free to use and modify.
For issues or suggestions, please reach out to the developer.
Built with ❤️ by Zain Aftab