Skip to content

A simple URL shortener with tracking features. This API allows you to shorten URLs and monitor user interactions, including IP and location tracking.

License

Notifications You must be signed in to change notification settings

MuhammedMagdyy/url-shortener

Repository files navigation

URL Shortener (aka. Tiny URL)

Node.js Express TypeScript Docker Ngrok MySQL Prisma

Table of Contents

Introduction

Have you ever had that moment when you send a funny video link to a friend, and then the suspense kicks in? Did they watch it? Did they laugh? Or did the link disappear into the void of unread messages? Well, one day, I decided enough was enough. Inspired by this very dilemma, I built a solution—a backend app that doesn’t just shorten URLs but also lets you know exactly when your friend opens the link by logging their IP and location. Sure, it might sound a little crazy (and okay, a bit like a digital detective), but it works! And now, I can rest easy knowing my comedy masterpiece didn’t go unnoticed. 😂

Prerequisites

  • Download and install Nodejs
  • Download and install MySQL using Docker from Docker Hub
  • A text editor (e.g. Visual Studio Code recommended)
  • A platform for testing APIs like Postman

Features

  • URL Shortening: Shorten long URLs into smaller ones.
  • Link Analytics: Track the geographical locations of users accessing the shortened URL.
  • IP & Location Logging: Log user IP addresses and their geographical location when they visit the shortened link.

Future Enhancements

  • Implement Link Expiration for time-limited URLs.
  • Investigate and handle VPN usage for more accurate analytics.
  • Enable Custom URL Patterns for personalized slugs.
  • Dockerize the Application.
  • API Documentation using Swagger.

Schema

schema

Setup

To set up this project locally, follow these steps:

  1. Clone the repository
https://github.com/MuhammedMagdyy/url-shortener 
  1. Change the project's directory
cd url-shortener
  1. Install required packages using npm install

  2. Rename the .env.example file to .env, then add your environment variables

  3. Run the following commands in order:

npm run prisma:migrate
npm run prisma:generate
npm run prisma:push
  1. Start the application:
    • Production: npm start
    • Development: npm run dev

Note

Exposing Local Server with ngrok

If you need to expose your local development server to the internet (for testing, or accessing the app remotely), you can use ngrok. It creates a secure tunnel from the public internet to your local machine.

Why ngrok?

We use ngrok to expose a local development server to the internet, especially in my case:

  • Tested How IPs getting logged with locations because it didn't work fine in localhost.
  • Access our local app from a remote location.

Steps to Use ngrok:

  1. Install ngrok:

    • Download and install ngrok from here.
  2. Authenticate ngrok:

    • Create a free account on ngrok.
    • Get your authtoken from the dashboard.
    • Authenticate with the command:
      ngrok authtoken <your-authtoken>
  3. Expose Your Local Server:

    • Start your local server (e.g., localhost:3000).

    • Run this command to expose it:

      ngrok http 3000
    • You will get a public URL (e.g., (https://<random-string>.ngrok-free.app )) that tunnels to your local server.

  4. Access Your Local Server:

    • Use the public URL to access your local app from anywhere (e.g. make an HTTP request from Postman).

About

A simple URL shortener with tracking features. This API allows you to shorten URLs and monitor user interactions, including IP and location tracking.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published