A simple Node.js Weather API wrapper using OpenWeatherMap.
Fetch current weather or daily forecast for any city.
GET /weather
Query Parameters
- city
Type: string
Required: No
Default: "london"
Description: Name of the city to get current weather forSample Request
GET /weather?city=SpringfieldSample Response
{
"success": true,
"greetings": "Welcome to the Weather API",
"data": {
"location": "Springfield",
"list": {
"coord": {
"lon": -93.2982,
"lat": 37.2153
},
"weather": [
{
"description": "few clouds"
}
],
"main": {
"temp": 26.79,
"feels_like": 26.96,
"humidity": 45
},
"wind": {
"speed": 2.06
},
"clouds": {
"all": 20
}
/_ other fields omitted for brevity _/
}
}
}
GET /forecast
Query Parameters
- city
Type: string
Required: No
Default: "london"
Description: Name of the city to get forecast for- days
Type: number
Required: No
Default: 5
Description: Number of days to return in the forecastSample Request
GET /forecast?city=Springfield&days=2
Sample Response
{
"success": true,
"greetings": "Welcome to the Weather API-Forecast route",
"Data": [
{
"Location": "Springfield",
"date": "2025-09-27",
"maxTemp": "27.65 °C",
"minTemp": "15.05 °C",
"maxWindSpeed": "2.73 m/s",
"minWindSpeed": "0.75 m/s",
"avgWindSpeed": "1.72 m/s",
"maxHumidity": "77 %",
"minHumidity": "36 %",
"avgHumidity": "56.13 %",
"condition": "few clouds"
},
{
"Location": "Springfield",
"date": "2025-09-28",
"maxTemp": "29.82 °C",
"minTemp": "16.91 °C",
"maxWindSpeed": "1.98 m/s",
"minWindSpeed": "1.07 m/s",
"avgWindSpeed": "1.63 m/s",
"maxHumidity": "69 %",
"minHumidity": "30 %",
"avgHumidity": "54.13 %",
"condition": "broken clouds"
}
]
}Installation & Running
Clone the repo:
git clone https://github.com/Amitrajit007/node-weather-wrapperInstall dependencies:
npm installAdd your OpenWeatherMap API key in .env:
WEATHER_API_KEY = your_api_key_here;Run the server:
npm startServer will run at http://localhost:3000.
-
If city is not provided, "london" will be used by default.
-
If days is not provided for the forecast, the API returns 5 days by default.
-
maxTemp, minTemp, avgWindSpeed, and avgHumidity are formatted as strings with units for clarity.
-
If you want to perform calculations with these values, use parseFloat() to convert them back to numbers.
project-root
├── node_modules
├── src
│ ├── API
│ │ └── weather.js
│ ├── controllers
│ │ ├── forecast.controller.js
│ │ └── weather.controller.js
│ ├── routes
│ │ ├── forecast.routes.js
│ │ └── weather.routes.js
│ └── app.js
├── .env
├── .gitignore
├── package-lock.json
├── package.json
└── README.md