Skip to content

URL-shortener is a lightweight and efficient Node.js application designed to simplify and condense long URLs into short, shareable links. With a focus on speed and simplicity.

License

Notifications You must be signed in to change notification settings

jrmoha/URL-shortener

Repository files navigation

Overview

A URL shortener service creates a short url/aliases/tiny url against a long url.Moreover, when user click on the tiny url, he gets redirected to original url.

Tiny url are exceedingly handy to share through sms/tweets (where there is limit to number of characters that can be messaged/tweeted) and also when they are printed in books/magazines etc.(Less character implies less printing cost). In addition, it is easy and less error prone to type a short url when compared to its longer version.

Tech Stack

Server: Node, Express, MongoDB, Redis

Design Issues

alt text

Problems with above design :

There is only one WebServer which is single point of failure (SPOF) System is not scalable There is only single database which might not be sufficient for 60 TB of storage and high load of 8000/s read requests

Alternative Design

alt text

API Reference

Create new user

  POST /app/users/api/create
Body Type Description
email string Required. Your email
password string Required. Your password
passwordConfirmation string Required. Your password confirmation

Get API_KEY

  POST /app/users/api/login
Body Type Description
email string Required. email
password string Required. password

Assign new short-url

  POST /app/api/create
Body Type Description
API_KEY string Required. Your API_KEY
URL string Required. URL to be shorten

Redirect to original_url

  GET /${SHORT_URL}
Parameters Type Description
SHORT_URL string Required. the SHORT_URL assigned with original one

Repository Structure

└── URL-shortener/
    ├── config/
    │   └── default.ts
    ├── src/
    │   ├── controllers/
    │   │   ├── url.controller.ts
    │   │   └── user.controller.ts
    │   ├── errors/
    │   │   └── APIError.ts
    │   ├── middleware/
    │   │   ├── errorHandler.middleware.ts
    │   │   ├── logger.middleware.ts
    │   │   └── validateInput.middleware.ts
    │   ├── models/
    │   │   ├── url.model.ts
    │   │   └── user.model.ts
    │   ├── routes/
    │   │   ├── index.ts
    │   │   ├── url.route.ts
    │   │   └── user.route.ts
    │   ├── schema/
    │   │   ├── url.schema.ts
    │   │   └── user.schema.ts
    │   ├── services/
    │   │   ├── url.service.ts
    │   │   └── user.service.ts
    │   ├── utils/
    │   │   ├── connect.ts
    │   │    └── logger.ts
    │   └── server.ts
    ├── .env.example
    ├── .eslintrc.js
    ├── .prettierrc.json
    ├── package.json
    ├── tsconfig.json
    └── yarn.lock

Installation

  git clone https://github.com/jrmoha/URL-shortener.git
  cd URL-shortener

Install Typescript

yarn add typescript

Initialize Typescript

npx tsc --init

Install dependencies

yarn install

Start Server

yarn dev

Environment Variables

Find all in .env.example

Acknowledgements

About

URL-shortener is a lightweight and efficient Node.js application designed to simplify and condense long URLs into short, shareable links. With a focus on speed and simplicity.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published