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. 😂
- 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
- 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.
- 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.
To set up this project locally, follow these steps:
- Clone the repository
https://github.com/MuhammedMagdyy/url-shortener
- Change the project's directory
cd url-shortener
-
Install required packages using
npm install
-
Rename the
.env.example
file to.env
, then add your environment variables -
Run the following commands in order:
npm run prisma:migrate
npm run prisma:generate
npm run prisma:push
- Start the application:
- Production:
npm start
- Development:
npm run dev
- Production:
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.
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.
-
Install ngrok:
- Download and install ngrok from here.
-
Authenticate ngrok:
-
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.
-
-
Access Your Local Server:
- Use the public URL to access your local app from anywhere (e.g. make an HTTP request from Postman).