A React-based News Aggregator App
HeadlinesHub is a modern, responsive news aggregator app built with React and Vite. It fetches top headlines from various categories using the NewsAPI and displays them in a clean, user-friendly interface.
🔗 https://headlines-hub-react.vercel.app/
- 📰 Top Headlines: Fetch and display the latest news articles from multiple categories (Technology, Business, Sports, etc.)
- 🔄 Infinite Scroll: Load more articles seamlessly as you scroll
- 📅 Date Formatting: Display published dates in a user-friendly format
- 🌙 Dark Mode: Built-in dark theme for a sleek, modern look
- 📱 Responsive Design: Optimized for all screen sizes
- ⚡ Fast Refresh: Vite's lightning-fast development server
- ☁️ Serverless API: CORS-free news fetching via Vercel serverless functions
| Category | Technology |
|---|---|
| Frontend | React 18, React Router 7 |
| Styling | Bootstrap 5.3 |
| Build Tool | Vite 6 |
| API | NewsAPI |
| Deployment | Vercel |
| Serverless | Vercel Functions |
headlineHUB/
├── api/
│ └── news.js # Vercel serverless function
├── src/
│ ├── assets/
│ │ └── logos.png
│ ├── components/
│ │ ├── Navbar.jsx
│ │ ├── NewsComp.jsx
│ │ ├── NewsDisplay.jsx
│ │ └── Spinner.jsx
│ ├── App.jsx
│ ├── main.jsx
│ ├── index.css
│ └── App.css
├── vercel.json # Vercel config for SPA routing
├── vite.config.js
├── package.json
└── README.md
- Node.js (v16 or higher)
- npm or yarn
- NewsAPI key from newsapi.org
-
Clone the repository:
git clone https://github.com/darshan-gowdaa/headlinesHub-React.git cd headlinesHub-React -
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env
Edit
.envand add your NewsAPI key:VITE_API_KEY=your_api_key_here
-
Start the development server:
npm run dev
-
Open in browser: Visit
http://localhost:5173
- Push your code to GitHub
- Import the repository on Vercel
- Add environment variable:
- Name:
VITE_API_KEY - Value: Your NewsAPI key
- Name:
- Deploy!
Note: The app uses a serverless function (
api/news.js) to bypass CORS restrictions in production. NewsAPI only allows browser requests fromlocalhost.
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run preview |
Preview production build |
npm run lint |
Run ESLint |
NewsAPI free tier has usage limits:
- 100 requests/day for free accounts
- Requests only work from localhost in browser (production uses serverless proxy)
If you see a "rate limit exceeded" message, wait 24 hours or get your own API key.
- Bootstrap 5: Responsive layouts and components
- Custom CSS: Animations, dark theme, and custom styles in
index.css
