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
urlin the request with or without aslug. - The server checks if the
urlis valid or not. - If the
urlis valid, the server checks if theslugis already taken or not. - If the
slugis not taken, the server saves theurland theslugin the database. - The server creates different versions of the shortened
urland based on theuser-agentheader, the server sends the appropriate version of the shortenedurlto 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
.envfile in the root directory of the project and add the following variables check the.env.examplefile
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 startfirst, 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 upThe project uses Jest as a testing framework and Supertest to test the API endpoints.
To run the tests, run the following command
npm testand here is a screenshot of some of the test results
