A lightweight and efficient URL shortener built with Node.js, Express.js, and MongoDB Atlas. Users can shorten long URLs, share them, and track click analytics. The project features rate limiting, input validation, and a simple web interface.
Try the deployed app here: https://url-shortener-xi-bay.vercel.app/
Roadmap Projects Link : https://roadmap.sh/projects/url-shortening-service
URL-Shortener/
│-- config/
│ └── db.js # Database connection setup
│-- controllers/
│ └── url.controller.js # Business logic for URL operations
│-- middlewares/
│ ├── asyncWrapper.js # Async error handling middleware
│ └── validator.middleware.js # Validation middleware
│-- models/
│ └── shortUrl.model.js # Mongoose schema/model for URLs
│-- routes/
│ └── url.routes.js # API endpoints for URL operations
│-- utils/
│ └── url.validator.js # URL validation logic
│-- views/
│ └── index.ejs # Frontend template
│-- server.js # Main entry point (Express server)
│-- package.json # Project metadata and dependencies
│-- vercel.json # Vercel deployment config
│-- page-image.jpg # Screenshot preview
│-- README.md # Project documentation
│-- .env # Environment variables (not committed)
│-- .gitignore # Git ignore file- Node.js installed
- MongoDB Atlas account
Follow these steps to set up the project locally:
- Clone the repository
git clone https://github.com/Mahmoud142/URL-Shortener.git
- Navigate to the project directory
cd URL-Shortener - Install dependencies
npm install
- Create a
.envfile in the root directory and add your MongoDB Atlas connection string:DB_URL=your_mongodb_atlas_connection_string
- Start the server
npm run dev # or node server.js - Open your browser and go to: http://localhost:3000/
- Shorten long URLs
- Track number of clicks for each short URL
- Input validation and error handling
- Rate limiting to prevent abuse
- Simple web interface (Bootstrap)
- MongoDB Atlas for cloud database
- Ready for deployment on Vercel
Contributions are welcome! Feel free to fork this repository, make improvements, and submit a pull request.
