A full-stack URL shortener built using the MERN stack (MongoDB, Express, React, Node.js). It allows users to shorten long URLs and track click analytics with a clean, responsive UI.
- 🔒 Shorten any valid long URL into a short one
- 📊 View click count analytics for each short link
- 🕒 Automatically stores creation date for each short URL
- 💾 Local history of past shortened URLs using
localStorage
- 🔁 Duplicate prevention with existing short URL reuse
- ✅ React Icons & Toastify UI feedback
- 🌐 Redirect short URL to original link
- ✨ Built with TailwindCSS and React
/url-shortner
├── /backend
│ ├── controllers/
│ ├── models/
│ ├── routes/
│ ├── config/
│ └── server.js
├── /frontend
│ ├── components/
│ ├── api/
│ ├── App.jsx
│ └── main.jsx
Description: Create a short URL
{
"url": "https://example.com"
}
{
"message": "Short URL created successfully",
"short_url": "http://localhost:5000/abc123",
"original_url": "https://example.com"
}
Description: Redirects to original URL
Example:
GET http://localhost:5000/abc123
→ redirects to https://example.com
Description: Returns click analytics
{
"short_code": "abc123",
"original_url": "https://example.com",
"click_count": 12,
"created_at": "2025-07-12T10:24:53.245Z"
}
- Frontend: React, TailwindCSS, React Icons, Toastify
- Backend: Node.js, Express
- Database: MongoDB
- Tools: Mongoose, Axios
- User enters a long URL in the frontend.
- The frontend calls the backend API to generate a unique
short_code
using nanoid. - The backend stores the mapping in MongoDB.
- The frontend saves the result in
localStorage
and updates the UI. - Clicking the short URL triggers redirection via Express.
- Click count is incremented on each visit.
-
Clone the Repository
git clone https://github.com/sharmaHarshit2000/url-shortener.git cd url-shortener
-
Setup Backend
cd backend npm install
Create
.env
file:PORT=5000 MONGO_URI=<your_mongodb_uri> BASE_URL=http://localhost:5000
Start the server:
npm run dev
-
Setup Frontend
cd ../frontend npm install npm run dev
Basic manual testing done using Postman and browser:
- Short URL generation
- Redirection behavior
- Click count increment
- Analytics fetch
- UI/UX with form validations
- Frontend (Vercel): https://url-shortener-topaz-six.vercel.app
- Backend (Render): https://url-shortener-3u7c.onrender.com
Harshit Sharma
📧 harshitsharma9989@gmail.com
🌐 GitHub