Skip to content

Prerit008/url-shortner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”— URL Shortener API

A simple and efficient URL shortener service built with Node.js, Express, and MongoDB. Generate short links that redirect to original URLs โ€” perfect for personal projects, frontend integration, or learning backend development.


๐Ÿš€ Features

  • Generate unique short URLs
  • Redirect to original URLs via short codes
  • Simple and clean REST API
  • Click tracking
  • Easy MongoDB setup via .env
  • Modular and scalable project structure

๐Ÿ“ฆ Tech Stack

  • Node.js + Express โ€“ Fast and flexible backend framework
  • MongoDB + Mongoose โ€“ Schema-based database modeling
  • nanoid โ€“ For generating unique short codes

๐Ÿ› ๏ธ Installation

git clone https://github.com/Prerit008/url-shortner.git
cd url-shortener
npm install


โš™๏ธ Environment Setup

Create a .env file in the root directory with the following variables:

PORT=5000
MONGO_URI=mongodb://localhost:27017/urlshortener
BASE_URL=http://localhost:5000

Replace MONGO_URI with your MongoDB Atlas URI if you're deploying online.


๐Ÿงช Running the Project

npm run dev   # For development with nodemon
npm start     # For production


๐Ÿ“ฎ API Endpoints

โž• POST /shorten

Request Body:

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

Response:

{"shortUrl": "http://localhost:5000/abc123X"}

๐Ÿ” GET /:code

Redirect to the original URL using the short code.

Visit http://localhost:5000/abc123X in your browser and it will redirect you to the original URL.


๐Ÿ’ป Frontend (HTML + Tailwind CSS)

A simple and elegant frontend is included with the project using HTML + Tailwind CSS. It provides a minimal UI to interact with the backend and shorten URLs.

๐Ÿงช How to Use:

  • Open the index.html file in your browser.
  • Enter any valid long URL e.g., https://www.google.com.
  • Click the "Shorten URL" button.
  • The shortened URL will appear below the input and link to the original.
  • Make sure your backend http://localhost:5000 is running before using the frontend.

You can customize this page, integrate it into a bigger app, or deploy it as a standalone client on Vercel, Netlify, or similar platforms.


๐Ÿ™Œ Contributing

Contributions are welcome! Feel free to open issues, suggest new features, or submit pull requests to improve this project.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published