Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dennis-mureti/shorten_url
https://github.com/dennis-mureti/shorten_url
chai express javascript mongodb mongoose nodejs
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/dennis-mureti/shorten_url
- Owner: dennis-mureti
- Created: 2024-07-16T10:55:09.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-16T12:31:28.000Z (4 months ago)
- Last Synced: 2024-10-02T06:21:58.466Z (about 1 month ago)
- Topics: chai, express, javascript, mongodb, mongoose, nodejs
- Language: JavaScript
- Homepage:
- Size: 3.53 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is a simple URL shortening service built with Node.js, Express, and MongoDB. The service allows users to submit a URL to be shortened and then redirect users from the shortened URL to the original URL.
Prerequisites
Node.js (v18.18.1 or higher)
npm (9.8.1 or higher)
MongoDB (You can use a local MongoDB instance or a MongoDB Atlas cluster)
SetupClone the repository
- git clone https://github.com/dennis-mureti/shorten_url.git
- cd shorten_urlInstall dependencies
- npm install / yarn installRun the server
- npm start / npm run dev
This will start the server on port 3000.API Endpoints
1. Create a shortened URL
URL: /api/shorten
Method: POSTRequest Body:
{
"name": "example",
"originalUrl": "https://www.example.com"
}Response:
{
"status": true,
"shortenedUrl": "randomId"
}2. Get all shortened URLs
URL: /api/shortened
Method: GETResponse:
Copy code
[
{
"_id": "60c73c41e8d1f82f4c8b4567",
"name": "example",
"originalUrl": "https://www.example.com",
"shortenedUrl": "randomId",
"__v": 0
}
]3. Redirect to the original URL
URL: /:shortUrlId
Method: GETResponse:
Redirects to the original URL. If the shortened URL is not found, returns a 404 status with the message "URL not found".Running Tests
To run the tests, use the following command:
- npm test