A URL shortener decreases the length of a URL for you. Large URLs can be complicated to remember or share with others. A shortened URL version can help you share your favorite link more easily.
This project has been deployed on cyclic.sh and you can check it out here.
In this project, I used the following technologies:
- The user gives a
url
in the request with or without aslug
. - The server checks if the
url
is valid or not. - If the
url
is valid, the server checks if theslug
is already taken or not. - If the
slug
is not taken, the server saves theurl
and theslug
in the database. - The server creates different versions of the shortened
url
and based on theuser-agent
header, the server sends the appropriate version of the shortenedurl
to the user.
You can use the following url form postman docs to check all the endpoints.
https://documenter.getpostman.com/view/22483128/2s93m32NqR
- Clone the repository
git clone https://github.com/Diaa-Hassan/URL-Shortner.git
- Create a
.env
file in the root directory of the project and add the following variables check the.env.example
file
touch .env
echo "PORT=5000" >> .env
echo "MONGO_URI=<your-mongodb-uri>" >> .env
echo "HOST=http://localhost:5000" >> .env
- Install the required packages
npm install
- Start the server
npm start
first, you need to install Docker and Docker-Compose on your machine. You can follow the instructions on the official website here
- Clone the repository
git clone https://github.com/Diaa-Hassan/URL-Shortner.git
- on the root directory of the project, run the following command
docker-compose up
The project uses Jest as a testing framework and Supertest to test the API endpoints.
To run the tests, run the following command
npm test
and here is a screenshot of some of the test results