This is an URL shortener service like bit.ly or cutt.ly. The front-end is not covered here. The API service can take a long URL and convert it to a shorter URL. MongoDB is used as the database. The long URL, short URL, and other details are stored in the database. When a long URL that is already stored in the database is passed again, it returns the older shortened URL.
Clone the project
git clone https://github.com/nemo0/node-url-shortener
Go to the project directory
cd urlShortenerMongo
Install dependencies
npm install
Start the server
npm run start
POST /api/short
Field | Type | Description |
---|---|---|
Body | json |
Original Url |
Example:
POST http://localhost:3333/api/short
Content-Type: application/json
{
"origUrl": "https://nemo.hashnode.dev/an-introduction-to-recursion-using-javascript-ckfgx2nrq001xols17h787f87"
}
GET /:id
Parameter | Type | Description |
---|---|---|
id |
string |
Unique URL Code |
Example:
GET http://localhost:3333/SLiCKEXdn
To run this project, you will need to add the following environment variables to your .env
file
Variable | Description |
---|---|
MONGO_URI |
MongoDB URI |
BASE |
Base URL for Shortening |