A modern, responsive weather application built using Next.js 14 and Tailwind CSS. This app provides real-time weather data for any city worldwide, utilizing the OpenWeatherMap API. The Weather App allows users to search for a city's current weather conditions, including temperature, humidity, wind speed, and a dynamic weather icon that changes based on the weather.
You can try the game live here!
- Features
- Getting Started
- Installation
- Usage
- Components
- API Integration
- Technologies Used
- Best Practices
- Contributing
- License
- Real-time weather data fetching from the OpenWeatherMap API.
- Dynamic icons that change based on weather conditions (e.g., clear, rain, mist, drizzle, clouds, snow, wind).
- Responsive design with Tailwind CSS, optimized for both desktop and mobile devices.
- Error handling for invalid city names or network issues.
- User-friendly UI with search functionality.
- Displays temperature, humidity, wind speed, and weather conditions.
To get a local copy of this project up and running, follow these steps.
- Node.js (v14 or higher)
- npm or yarn (package manager)
-
Clone the repository:
git clone https://github.com/aryansoni-git/weather-app.git cd weather-app
-
Install dependencies:
npm install # or yarn install
-
Get an API key from OpenWeatherMap:
- Visit OpenWeatherMap and sign up to get your API key.
-
Set up environment variables:
- Create a
.env.local
file in the root directory and add your API key:NEXT_PUBLIC_OPENWEATHERMAP_API_KEY=your_api_key_here
- Create a
-
Run the application:
npm run dev # or yarn dev
-
Visit the app in your browser:
- Open http://localhost:3000 to view the app.
- Enter the name of the city in the search bar.
- Click on the "Search" button.
- The app will fetch and display the current weather data, including temperature, humidity, wind speed, and the corresponding weather icon.
- WeatherApp.jsx: The main component that manages state and handles API requests.
- Search.jsx: A component for the search input and button, allowing users to search for a city.
- Card.jsx: A reusable component that displays weather data such as temperature, humidity, wind speed, and icons.
The app uses the OpenWeatherMap API to fetch weather data. It sends a request with the city name and receives the current weather conditions.
- Endpoint:
https://api.openweathermap.org/data/2.5/weather
- Parameters:
q
: City nameappid
: Your API keyunits
: Units of measurement (e.g.,metric
for Celsius)
Example of an API call:
axios.get(
`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=${API_KEY}`
);
- Next.js 14: A React framework for building server-rendered applications.
- Tailwind CSS: A utility-first CSS framework for building responsive layouts.
- Axios: A promise-based HTTP client for making API requests.
- JavaScript (ES6+): The core language for building the app.
- Environment Variables: Securely manage API keys using environment variables.
- Component Reusability: Modular and reusable components like
Card
for displaying data. - Error Handling: Display user-friendly messages for errors and loading states.
- Optimized API Requests: Use
useEffect
for initial data fetching and caching to avoid excessive API calls.
Contributions are welcome! Please fork the repository and create a pull request with your changes. Ensure your code follows the project's coding standards and is well-documented.
This project is licensed under the MIT License. See the LICENSE file for more details.