Skip to content

Diaa-Hassan/URL-Shortner

Repository files navigation

URL-Shortner

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.

Tech Stack

In this project, I used the following technologies:

How it works

  1. The user gives a url in the request with or without a slug.
  2. The server checks if the url is valid or not.
  3. If the url is valid, the server checks if the slug is already taken or not.
  4. If the slug is not taken, the server saves the url and the slug in the database.
  5. The server creates different versions of the shortened url and based on the user-agent header, the server sends the appropriate version of the shortened url to the user.

API Endpoints

You can use the following url form postman docs to check all the endpoints.

https://documenter.getpostman.com/view/22483128/2s93m32NqR

How to use locally

  1. Clone the repository
git clone https://github.com/Diaa-Hassan/URL-Shortner.git
  1. 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
  1. Install the required packages
npm install
  1. Start the server
npm start

How to use locally with Docker

first, you need to install Docker and Docker-Compose on your machine. You can follow the instructions on the official website here

  1. Clone the repository
git clone https://github.com/Diaa-Hassan/URL-Shortner.git
  1. on the root directory of the project, run the following command
docker-compose up

Testing

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

Languages