Simple URL Shortener
This project is a Simple URL Shortener developed as part of the CodeAlpha Backend Development Internship.
The application takes a long URL from the user, generates a short and unique URL, stores the mapping in a MongoDB database, and redirects users to the original URL when the short link is accessed.
What the project does
- Generates short URLs for long links
- Redirects short URLs to the original website
- Stores URLs in MongoDB
- Avoids duplicate entries for the same URL
- Validates incorrect or empty input
- Shows user-friendly error messages
- Includes a simple and aesthetic frontend interface
Technologies used
- Node.js
- Express.js
- MongoDB
- Mongoose
- HTML, CSS, and JavaScript
Project structure
CodeAlpha_URL_Shortener
src
- config (database connection)
- models (MongoDB schemas)
- controllers (application logic)
- routes (API routes)
- app.js
public (frontend files)
server.js (server entry point)
.env (environment variables)
README.md
API endpoints
POST /shorten
This endpoint accepts a long URL and returns a shortened URL.
Example request body: originalUrl: https://example.com
GET /:shortCode
This endpoint redirects the user to the original URL associated with the short code.
How to run the project locally
-
Clone the repository
git clone https://github.com/your-username/CodeAlpha_URL_Shortener.git -
Navigate to the project folder
cd CodeAlpha_URL_Shortener -
Install dependencies
npm install -
Create a .env file and add your MongoDB connection string
MONGO_URI=your_mongodb_connection_string -
Start the server
node server.js -
Open your browser and visit
http://localhost:5000
Internship information
Organization: CodeAlpha
Domain: Backend Development
Task: Simple URL Shortener
Learning outcomes
This project helped me strengthen my understanding of backend development, REST API design, MongoDB integration, input validation, error handling, and writing clean, structured code.
Thank you for reviewing my project.