Weather-Check is a simple Node.js backend project that fetches weather data for a given location using the OpenWeatherMap API. This project is designed to showcase backend development skills, including API integration, environment variable management, and error handling.
- Fetch weather data by latitude and longitude
- Simple and easy-to-understand code structure
- Environment variable management using dotenv
- Error handling for API requests
- Node.js (v14.x or higher)
- npm (v6.x or higher)
- OpenWeatherMap API key
-
Clone the repository:
git clone https://github.com/your-username/Weather-Check.git cd Weather-Check -
Install dependencies:
npm install
-
Create a
.envfile in the root directory and add your OpenWeatherMap API key:WEATHER_API_KEY=your_api_key_here
-
Start the server:
node src/index.js
-
The server will be running on port 3000 by default. You can access it at:
http://localhost:3000/weather?lat={latitude}&lon={longitude}Example:
http://localhost:3000/weather?lat=51.5074&lon=-0.1278
-
GET /weather
Fetch weather data by latitude and longitude.
Query Parameters:
lat(required): Latitude of the location.lon(required): Longitude of the location.
Response:
{ "coord": { "lon": -0.1278, "lat": 51.5074 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ], "base": "stations", "main": { "temp": 14.85, "feels_like": 13.85, "temp_min": 13.33, "temp_max": 16.11, "pressure": 1012, "humidity": 82 }, "visibility": 10000, "wind": { "speed": 1.54, "deg": 90 }, "clouds": { "all": 0 }, "dt": 1598301750, "sys": { "type": 1, "id": 1414, "country": "GB", "sunrise": 1598245640, "sunset": 1598296611 }, "timezone": 3600, "id": 2643743, "name": "London", "cod": 200 }
Contributions are welcome! Please open an issue or submit a pull request for any bugs or enhancements.