Skip to content

Amitrajit007/node-weather-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather API

A simple Node.js Weather API wrapper using OpenWeatherMap.
Fetch current weather or daily forecast for any city.


Base URL

http://localhost:3000


Endpoints

1. Get Current Weather

GET /weather

Query Parameters

- city
  Type: string
  Required: No
  Default: "london"
  Description: Name of the city to get current weather for

Sample Request

GET /weather?city=Springfield

Sample 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 _/
}
}
}

2. Get Weather Forecast

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 forecast

Sample 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-wrapper

Install dependencies:

npm install

Add your OpenWeatherMap API key in .env:

WEATHER_API_KEY = your_api_key_here;

Run the server:

npm start

Server will run at http://localhost:3000.

Notes

  • 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 Structure

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

About

Simple weather API wrapper built with Node.js and Express.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published