https://github.com/barcodehub/short-url-node
https://github.com/barcodehub/short-url-node
short-url
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/barcodehub/short-url-node
- Owner: Barcodehub
- Created: 2024-08-04T20:22:02.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-04T20:34:10.000Z (10 months ago)
- Last Synced: 2025-02-11T15:53:26.510Z (3 months ago)
- Topics: short-url
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ShortURL - URL Shortening Service
ShortURL is a robust and efficient backend application for shortening URLs, built with Node.js, Express, and MongoDB. This application provides a RESTful API that allows users to shorten long URLs and redirect to the original URLs using generated short codes.
## Features
- Shortening of long URLs
- Redirection to original URLs
- Generation of unique short codes
- Persistent storage in MongoDB
- RESTful API## Prerequisites
- Node.js (v14.0.0 or higher)
- MongoDB## Installation
Install dependencies:
```
npm install
```Create a `.env` file in the root of the project and add the following environment variables:
```
PORT=3000
MONGO_URI=mongodb://localhost:27017/shorturl
```
Make sure to replace the MongoDB URI with the correct one for your environment.## Starting the server
For development:
npm run devThe server will start in the PORT `http://localhost:3000` (or the port you specified in the `.env` file).
## API Endpoints
Shorten a URL
- Method: POST
- Path: `PORT/shorten`
Body: `{
"url": "https://www.example.com/long-url-to-shorten"
}`
Redirect to original URL
- Method: GET
- Path: `PORT/:shortCode`
- Response: Redirection to the original URL## Technologies Used
- Node.js
- Express.js
- MongoDB
- shortid