A simple and efficient web application to shorten long URLs, built with React (frontend), Node.js + Express (backend), and MongoDB. Includes an admin page to view all shortened URLs and their visit statistics.
- Shorten any long URL to a simple, shareable link
- Redirects short URLs to the original long URL
- Tracks the number of visits for each short URL
- Admin page to view all shortened URLs and stats
- Node.js (v16+ recommended)
- MongoDB (local or cloud instance)
-
Clone the repository:
git clone https://github.com/Aditya-Mishra9670/URLshortner.git cd URLshortner -
Backend Setup:
cd server npm install # Create a .env file (see below for example) npm start
Example
.envfor backend:MONGO_URI=mongodb://127.0.0.1:27017/urlShortener BASE_URL=http://localhost:5000 PORT=5000
-
Frontend Setup:
cd ../client/urlshortner npm install # Create a .env file (see below for example) npm run dev
Example
.envfor frontend:VITE_API_URL=http://localhost:5000/api/shorten
- Open the frontend in your browser (default: http://localhost:5173 or http://localhost:3000)
- Enter a long URL in the input form and submit.
- Copy the generated short URL and share it.
- Visiting the short URL will redirect to the original long URL.
- Click the "Go to Admin Page" button in the UI.
- View all shortened URLs and their visit counts.
- POST
/api/shorten - Body:
{ "url": "https://www.example.com/very/long/path" } - Response:
{ "shortUrl": "http://localhost:5000/abc123" }
- GET
/:code - Description: Redirects to the original URL for the given short code.
- Example:
GET http://localhost:5000/abc123→ Redirects to the original URL.
- GET
/api/urls - Response:
[ { "_id": "...", "originalUrl": "https://www.example.com/very/long/path", "shortCode": "abc123", "shortUrl": "http://localhost:5000/abc123", "visitCount": 5, "createdAt": "2025-08-26T12:34:56.789Z" }, ... ]
URLshortner/
├── client/
│ └── urlshortner/
│ ├── src/
│ ├── .env
│ └── ...
├── server/
│ ├── index.js
│ ├── .env
│ └── ...
└── README.md
This project is licensed under the MIT License.