A simple backend project for shortening URLs using Node.js, Express.js, and MongoDB.
- Create short URLs for any valid long URL.
- Retrieve the original long URL using the short link.
-
Clone the repository:
git clone https://github.com/mohsen104/Link-Shortener.git cd Link-Shortener
-
Install dependencies:
npm install
-
Start the server:
npm start
By default, the server will run on
http://localhost:3000
.
- URL:
/api/shortener
- Method:
POST
- Request Body:
{ "originalUrl": "http://localhost:3000/api/shortener" }
- Response:
{ "message": "created", "shortId": "@shortId" }
- URL:
api/s/:shortId
- Method:
GET
- Response (Redirect): Redirects the user to the original URL.
├── configs/ # Config for connect to database
├── models/ # MongoDB models
├── controllers/ # Business logic for API routes
├── main.js # Express app initialization, Server entry point
└── readme.md # Project documentation
- Node.js: Server-side JavaScript runtime.
- Express.js: Web framework for building APIs.
- MongoDB: Database for storing original and short URLs.
Contributions are welcome! Feel free to fork this repository and submit pull requests.