This is an URL shortener service . Only the backend part is covered here. The API service can take a long URL and convert it to a shorter URL.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/Aniketsinghcoder/URL-Shortener.git
Go to the project directory
cd URL-Shortener
Install dependencies
npm install
Start the server
node app.js
POST /api/short
Field | Type | Description |
---|---|---|
Body | json |
Original Url |
Example:
POST http://localhost:3333/api/short
Content-Type: application/json
{
"origUrl": "https://www.google.com/"
}
Because we have used MongoDB, we’ll need a MongoDB SRV URI. You can create a database from this link.
Now, create a .env
file to store the MongoDB SRV URI and the base URL, to run this project. The base URL will be your local host server location for now. Here’s my .env file code:
MONGO_URI=mongodb+srv://username:password@cluster0.mkws3.mongodb.net/DB_NAME?retryWrites=true&w=majority
BASE=http://localhost:3333
Remember to change the <username> , <password> & <DB_NAME>
field in the MongoDB URI with your database username , password & database name.
NodeJS | ExpressJS | MongoDB |
---|