Weather app with a free API
Search any city and see current weather and a 7-day forecast, using the free Open-Meteo API (no key needed).
What you'll learn
- âfetch, async/await and JSON
- âHandling loading and errors
- âGeolocation API
What you'll build
- âCity search with suggestions
- âCurrent temperature, wind and condition icon
- â7-day forecast
- âUse my location button
Step-by-step guide
- 1
Find the city
Call https://geocoding-api.open-meteo.com/v1/search?name=Jaipur to get latitude and longitude.
- 2
Get the weather
Call https://api.open-meteo.com/v1/forecast?latitude=..&longitude=..¤t=temperature_2m,weather_code,wind_speed_10m&daily=temperature_2m_max,temperature_2m_min,weather_code&timezone=auto.
- 3
Map weather codes
Open-Meteo returns WMO weather codes; map them to text and an emoji or icon (0 = clear, 61 = rain, ...).
- 4
Render
Build the current card and 7 forecast cards with template literals; format days with toLocaleDateString.
- 5
Loading and errors
Show a spinner while fetching; show "City not found" or "Network error" instead of failing silently.
- 6
My location
navigator.geolocation.getCurrentPosition gives coordinates; skip the geocoding step.
- 7
Remember
Save recent searches in localStorage and show them as chips.
đ Make it stand out
- +Hourly chart with Chart.js
- +°C/°F toggle
- +Background that changes with the weather