The URL Shortener service is a Node.js-based web application that allows users to shorten long URLs into compact, shareable links. The service supports redirection from the short URL to the original URL. The system leverages Redis for caching to ensure optimized response times, high performance, and scalability.
To get started with the project, first clone the repository to your local machine:
git clone https://github.com/yourusername/url-shortener.git
cd url-shortener
Install all required dependencies using npm:
npm install
Create a .env
(All credentials are given in the Documentation pdf) file in the root directory with the following configurations:
BASE_URL=http://localhost:8080
MONGO_URI=your_mongo_database_uri
REDIS_URI=your_redis_instance_uri
Start the development server:
npm run dev
The application uses the MVC (Model-View-Controller) design pattern:
- Model: Schema for storing URLs
- Controller: Handles core logic and validation
- View: Not applicable (REST API)
- Utilities: Error handling and Redis integration
POST /api/urls/compressUrl
Request body:
{
"originalUrl": "https://codinito.com"
}
Success Response (200):
{
"statusCode": 200,
"data": "Existing URL fetched",
"message": {
"_id": "676a265b8ec83090b66adbbe",
"shortId": "_gzlmvdij",
"shortUrl": "http://localhost:8080/api/urls/_gzlmvdij",
"originalUrl": "https://codinito.com",
"createdAt": "2024-12-24T03:11:23.847Z",
"updatedAt": "2024-12-24T03:11:23.847Z"
},
"success": true
}
GET /api/urls/:shortId
Response: Redirects to original URL (Status 302)
- Node.js and Express.js
- Redis for caching
- MongoDB for storage
- MVC architecture
- Cloud deployment
- Authentication system
- Rate limiting
- Usage analytics