This repository contains a Node.js and Express.js backend application designed for managing URL shortening operations through a RESTful API. It provides endpoints for creating shortened URLs and redirecting to original URLs based on the shortened link. It also serves a landing page and a custom 404 error page for invalid URLs.
-
URL Shortening
- Create shortened URLs from long URLs.
- Redirect to the original long URL using the shortened link.
-
Custom Pages
- Serve a static landing page.
- Serve a custom 404 error page for invalid shortened URLs. (credits to https://github.com/tsparticles/404-templates)
- Backend: Node.js, Express.js
- Database: MySQL
- Additional Libraries: dotenv for environment configuration, body-parser for JSON parsing, cors for handling Cross-Origin Resource Sharing
-
Clone the repository:
git clone https://github.com/PhilCode-creator/URL-Shortener.git cd url-shortener-service -
Install dependencies:
npm install
-
Configure environment variables:
- Create a
.envfile in theconfigdirectory. - Define necessary variables (e.g., database connection string).
- Create a
-
Start the server:
npm start
-
Endpoint:
POST /api/create/addURL -
Body:
{ "url": "https://example.com/long-url" } -
Response:
{ "success": true, "shortenedURL": "https://your-website.com/abcd1234" }
- Endpoint:
GET /:shortenedURL - Description: Redirects to the original long URL using the shortened URL.
- Responses:
- Success: Redirects to the original URL.
- Invalid URL: Serves the custom 404 page.
- Internal Server Error: Returns a plain text error message.
Feel free to contribute by forking the repository and submitting pull requests for new features or bug fixes.
This project is licensed under the MIT License.