A JavaScript web application that fetches and displays real-time weather data using the OpenWeatherMap API, based on user input or current location.
- Search weather by city name
- Display temperature, weather condition, and icon
- Fetch weather using user's current geolocation
- Dynamic UI updates without page reload
- Clean and modular JavaScript structure after refactoring
- JavaScript (ES6)
- HTML & CSS
- Bootstrap 5
- OpenWeatherMap API
- Browser Geolocation API
- Fetch API
The application interacts with the OpenWeatherMap API to retrieve real-time weather data.
- Users can input a city name via a form
- The app sends a request to the API using
fetch - Weather data is parsed and rendered dynamically in the DOM
- Users can also click a location icon to:
- Retrieve their coordinates via the Geolocation API
- Fetch weather data based on latitude and longitude
The UI updates instantly without refreshing the page by preventing default form behavior.
This project requires an API key from OpenWeatherMap.
To run the app locally:
- Create a
config.jsfile inside thelib/directory - Add your API key:
const apiKey = "your_api_key_here"- The file is already referenced correctly in
index.html:
<script src="lib/config.js"></script>
<script src="lib/index.js"></script>- The
lib/config.jsfile is ignored via.gitignoreand is not included in this repository - A
lib/config.example.jsfile is provided as a reference for setup
Note: Since this is a frontend-only application, API keys cannot be fully secured. In a production environment, API calls should be handled through a backend.
git clone https://github.com/sp1aca9fa/weather.git
cd weatherThen run a local server:
npx serveOpen in your browser: http://localhost:3000
- Working with external APIs and handling JSON responses
- Using the Fetch API for asynchronous requests
- Handling user input and events in the DOM
- Using the browser Geolocation API
- Preventing default browser behavior (form submission)
- Refactoring JavaScript into reusable functions
This project is a solution to a Le Wagon bootcamp coding challenge, focused on practicing API integration and front-end JavaScript fundamentals.