A simple Node.js application built with Express.js to shorten URLs, manage them, and generate QR codes for the shortened URLs.
- Shorten a given URL.
- Redirect to the original URL using the shortened version.
- Generate and retrieve QR codes for shortened URLs.
- List all shortened URLs with their details.
Make sure you have the following installed on your machine:
- Clone the repository:
git clone https://github.com/georgegozal/nodejs_url_shortener_api.git cd nodejs_url_shortener_api - Install dependencies:
npm install
- Initialize Databse
sequelize init sequelize db:migrate
- Run the application:
npm start
- The server will be available at http://localhost:3000 (default).
-
Shorten a URL POST / Create a new shortened URL for a given original URL.
Request Body:
{ "url": "https://example.com" }
Response:
{
"success": true,
"message": "URL shortened successfully",
"data": {
"original": "https://example.com",
"shortened": "http://localhost:3000/abcde",
"qrCode": "http://localhost:3000/qr/abcde"
}
}
- Redirect to Original URL GET /:shortened Redirects to the original URL using the shortened version.
Example: Visiting http://localhost:3000/abcde redirects to https://example.com.
- List All URLs GET /urls/list Retrieves all shortened URLs with their details.
Response:
{
"success": true,
"data": [
{
"originalUrl": "https://example.com",
"shortenedUrl": "http://localhost:3000/abcde",
"createdAt": "2025-01-22T10:00:00Z",
"qrCode": "http://localhost:3000/qr/abcde"
}
]
}
- Get QR Code GET /qr/:shortened Retrieves the QR code for the given shortened URL.
Example: Request: http://localhost:3000/qr/abcde Response: Displays the QR code as an image.
License
This project is licensed under the MIT License. See the LICENSE file for details.