Skip to content

advi-cyber/URI-Shortener-Service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URI Shortener Service

Intern ID: CITS2448

Overview

URI Shortener Service is a RESTful API built using Node.js, Express.js, MongoDB Atlas, and Mongoose. The application allows users to generate shortened URLs, redirect to the original URLs, and track URL usage statistics.

Features

  • Shorten long URLs into unique short codes
  • Redirect users to the original URL
  • Track the number of clicks for each shortened URL
  • Store URL data in MongoDB Atlas
  • RESTful API architecture
  • Unique short code generation using NanoID

Tech Stack

  • Node.js
  • Express.js
  • MongoDB Atlas
  • Mongoose
  • NanoID
  • Dotenv

Project Structure

URI-Shortener-Service/
│
├── src/
│   ├── controllers/
│   │   └── urlController.js
│   │
│   ├── models/
│   │   └── Url.js
│   │
│   ├── routes/
│   │   └── urlRoutes.js
│   │
│   └── server.js
│
├── .env
├── package.json
├── package-lock.json
└── README.md

Installation

  1. Clone the repository
git clone <repository-url>
  1. Navigate to the project folder
cd URI-Shortener-Service
  1. Install dependencies
npm install
  1. Configure environment variables

Create a .env file and add:

MONGO_URI=your_mongodb_connection_string
PORT=5000
  1. Start the server
npm run dev

API Endpoints

Create Short URL

POST

/shorten

Request Body:

{
  "originalUrl": "https://google.com"
}

Response:

{
  "message": "Short URL created",
  "shortCode": "VvmXTT"
}

Redirect URL

GET

/:shortCode

Example:

/VvmXTT

Redirects to the original URL.


URL Statistics

GET

/stats/:shortCode

Example:

/ stats/VvmXTT

Response:

{
  "originalUrl": "https://google.com",
  "shortCode": "VvmXTT",
  "clicks": 1
}

Database Schema

Field Type Description
originalUrl String Original long URL
shortCode String Generated unique code
clicks Number Number of redirects

Future Enhancements

  • Custom short URLs
  • URL expiration
  • User authentication
  • QR code generation
  • Advanced analytics dashboard

Author

Advaita Praveen Kumar Parikkal

License

This project is developed for internship and learning purposes.

About

Backend service that transforms long URLs into short, shareable links using Node.js, Express.js, and MongoDB Atlas. Features include unique short code generation, URL redirection, click tracking, and RESTful API architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages