Skip to content

Mahmoud142/URL-Shortener

Repository files navigation

URL Shortener

Overview

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.

🌐 Live Demo

Try the deployed app here: https://url-shortener-xi-bay.vercel.app/

Roadmap Projects Link : https://roadmap.sh/projects/url-shortening-service

📂 Project Structure

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

📸 Screenshot

Screenshot Preview

🚀 Getting Started

📌 Prerequisites

🔧 Installation

Follow these steps to set up the project locally:

  1. Clone the repository
    git clone https://github.com/Mahmoud142/URL-Shortener.git
  2. Navigate to the project directory
    cd URL-Shortener
  3. Install dependencies
    npm install
  4. Create a .env file in the root directory and add your MongoDB Atlas connection string:
    DB_URL=your_mongodb_atlas_connection_string

⚡ Usage

  1. Start the server
    npm run dev
    # or
    node server.js
  2. Open your browser and go to: http://localhost:3000/

🌟 Features

  • 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

🤝 Contributing

Contributions are welcome! Feel free to fork this repository, make improvements, and submit a pull request.

About

URL Shortener using Node.js, Express.js, mongoose , mongoDB and Bootstrap

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors