A simple URL Shortener built using Node.js, Express.js, MongoDB, and EJS for the frontend. It allows users to shorten long URLs and access them using a short custom link.
- Backend: Node.js, Express.js
- Frontend: EJS
- Database: MongoDB (Mongoose ORM)
- 🔗 Shorten long URLs
- 🔄 Redirect short URLs to the original links
- 📊 Track the number of clicks on each shortened URL
- 📜 Simple and clean UI with EJS
git clone https://github.com/Sanketmandwal/URLshortner.git
cd URLshortnernpm installCreate a .env file in the project root and add:
PORT=8000
MONGO_URI=your_mongodb_connection_string
BASE_URL=http://localhost:8000npm startThe server will start at http://localhost:8000.
- Enter a long URL in the input field on the homepage.
- Click the "Generate" button.
- Get a shortened URL and share it.
- Click the shortened link to be redirected to the original URL.
📂 url-shortener
┣ 📂 views # EJS templates
┣ 📂 public # Static assets (CSS, JS, images)
┣ 📂 models # Mongoose schemas
┣ 📂 routes # Express routes
┣ 📂 controllers # Business logic
┣ 📜 server.js # Entry point
┣ 📜 .env # Environment variables
┣ 📜 package.json # Project dependencies
| Method | Endpoint | Description |
|---|---|---|
| POST | /url |
Shortens a URL |
| GET | /url/:shortId |
Redirects to the URL |
| GET | /url/analytics/:shortId |
Get URL click stats |
- ✅ Custom short URLs
- ✅ QR code generation for short links
Feel free to fork this repository, make changes, and submit a pull request!
This project is licensed under the MIT License.
💡 Created with ❤️ by [Sanket Mandwal]