A simple yet powerful weather scraper built with Node.js, Express, and Cheerio. This project dynamically fetches real-time weather data for any city, scrapes the necessary details, and presents them on an intuitive user interface. 🌍☀️🌧️
🔹 Real-Time Weather Data: Get instant updates on:
- 📅 Date
- 🌡️ Temperature (Current, Min & Max)
- 💧 Humidity
- 🔽 Pressure
🔹 Express-Powered API: A lightweight and efficient API built with Express.js.
🔹 Web Scraping Magic: Uses Axios to fetch and Cheerio to extract weather details effortlessly.
🔹 Beautiful & Responsive UI: Clean, minimal, and user-friendly interface for seamless interaction.
Before you get started, ensure you have:
✅ Node.js (v12 or later recommended) ✅ npm (Comes bundled with Node.js)
1️⃣ Clone the repository:
git clone https://github.com/GauravKarakoti/weather-api.git
cd weather-api2️⃣ Install dependencies:
npm install3️⃣ Set up environment variables:
cp .env.example .env(Update .env with required API endpoint, CSS selectors, and server port.)
🚀 Live Frontend Demo – Just enter a city name and get weather details instantly!
1️⃣ Start the server:
node server.js(Server runs on the port specified in .env, default: 3003)
2️⃣ Launch the Frontend:
- Open
index.htmlin a browser. - Or use Live Server for better performance.
3️⃣ Get Weather Updates:
- Enter a city name 📍
- Click Get Weather ☁️
- See real-time weather info! 🌡️
🌍 Weather API Backend – Fetch weather details via endpoints.
Example: Delhi Weather
weather-api/
│-- frontend/
│ ├── index.html # User Interface
│ ├── styles.css # Styling
│ ├── script.js # API Handling
│
│-- server/
│ ├── server.js # Express Backend
│ ├── scraper.js # Web Scraping Logic
│ ├── .env # Configurations
│ ├── package.json # Dependencies
│
└── README.md # Documentation
🛠️ Built With:
- Express.js – Fast & lightweight web framework 🚀
- Axios – Fetching HTML content effortlessly 🌐
- Cheerio – Scraping and parsing made easy 🧐
- CORS – Secure cross-origin requests 🔄
- dotenv – Manages environment variables 🔐
- Jest - Efficient And RObut management for testing 💪🏻
💡 Have suggestions or improvements? Open an issue or submit a pull request!
🔹 When testing locally, switch the API endpoint in index.html:
const apiUrl = `http://localhost:3003/${city}`;🔹 Before submitting a pull request, revert it to the deployed API.
🚀 Stay Ahead of the Weather – One City at a Time! 🌍☀️🌧️