The weather app was created using JavaScript, HTML, and CSS. This app allows users to search for a city and get current weather information such as temperature, humidity, and wind speed.
- Search for a city to view the weather
- Displays temperature, humidity, wind speed, and UV index
- Fetches weather data from the OpenWeatherMap API
Before running this project, make sure you have the following installed:
- Node.js (includes npm)
- You can download it from https://nodejs.org
You can check if you have Node.js installed by running:
node -v
npm -vClone the repository to your local machine and navigate into the project directory:
git clone https://github.com/Mayokun-Sofowora/weatherApp.git
cd weatherAppThis project uses dotenv to manage environment variables (API keys). To install the required npm package, run:
npm install- Sign up for an API key from OpenWeatherMap
- Create a
.envfile in the root of the project and add the following line:
API_KEY=your_openweathermap_api_keyReplace your_openweathermap_api_key with the key you received from OpenWeatherMap.
You can run the project using a local server to avoid issues with API requests.
If you have http-server installed globally, navigate to your project directory and run:
npm install -g http-serverAfter installation, start the server by running:
http-serverThis will start a local server with output similar to:
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://192.168.0.10:8080
Hit CTRL-C to stop the serverAlternatively, you can open the index.html file directly in your browser by double-clicking it. However, using a local server is recommended for better dynamic content handling.
Open your browser and navigate to:
http://localhost:8080
- Open the app in your browser
- Enter a city name in the search bar and press the search button to get weather data
- The app will display the current temperature, humidity, wind speed, and UV index for the city
index.html: The main HTML file containing the structure of the appstyle.css: The CSS file that handles the styling of the appscript.js: JavaScript file responsible for fetching weather data and handling interactions.env: Stores environment variables, such as the API key for OpenWeatherMap
- This app uses the OpenWeatherMap API to fetch weather data. Make sure to get an API key and add it to the
.envfile - If you want to modify the app to fetch data from another weather API, just replace the API URL and adjust the data processing in the
script.jsfile
- Make sure you've set up your
.envfile correctly and that your API key is valid
- Ensure the API response contains the expected data and that the JavaScript is correctly processing it
- Setup Instructions: Added detailed steps to install dependencies, set up environment variables, and run the app.
- API Key Setup: Clearly outlined how to obtain and configure the OpenWeatherMap API key.
- Local Server Instructions: Recommended using
http-serverfor running the app locally, but also included the option to open the HTML file directly in the browser. - Notes on Troubleshooting: Provided helpful troubleshooting tips in case the app doesn’t work as expected.
- Project Structure: Included an overview of the project structure so users understand the organization of files.