This is a backend service for shortening URLs. Users can provide a long URL, and the service generates a unique short URL. When someone visits the short URL, they are redirected to the original long URL. The backend is built using Node.js, Express, and MongoDB (via Mongoose).
- Shorten long URLs into a unique short URL.
- Store URLs and visit history in MongoDB.
- Keep track of timestamps for each visit.
- Fast and lightweight backend API for URL shortening.
- Node.js
- Express.js
- MongoDB & Mongoose
- shortid (for generating unique short URLs)
-
Short URL Generation:
- Each long URL is assigned a unique
shortIdusing theshortidlibrary. - The
shortIdis stored along with the original URL in MongoDB.
- Each long URL is assigned a unique
-
Database Schema:
- The URL schema has three main fields:
- shortId: Unique identifier for the short URL.
- redirectUrl: The original URL to redirect to.
- visitHistory: Array storing timestamps of each visit.
- Timestamps are automatically managed using Mongoose’s "timestamps" option.
- The URL schema has three main fields: