A production-ready URL Shortener built with the MERN Stack (MongoDB, Express, React, Node.js) using TypeScript, Drizzle ORM, and Next.js.
It provides a seamless way to shorten long URLs, track analytics, and manage links β all through a modern, responsive UI.
π Deployed App: URL-SHORTENER
β Shorten URLs instantly β Generate short, clean, shareable links π Track analytics β Count and monitor URL visits π§© Type-safe backend β Built entirely with TypeScript βοΈ Drizzle ORM β Lightweight, modern database layer π Responsive UI β Optimized for desktop and mobile π Fast build & runtime β Powered by Bun + Next.js βοΈ Deployed on Orchids β Cloud-ready and production optimized
| Layer | Technologies |
|---|---|
| Frontend | Next.js, React, TypeScript, TailwindCSS |
| Backend | Node.js, Express.js, Drizzle ORM |
| Database | MongoDB |
| Build Tool | Bun |
| Deployment | Vercel Platform |
π¦ URL_shortner
βββ drizzle/ # Database ORM setup (Drizzle)
βββ public/ # Static assets
βββ src/ # Source code
β βββ components/ # React UI components
β βββ pages/ # Next.js pages
β βββ lib/ # Utility and helper functions
β βββ server/ # Express backend logic
βββ middleware.ts # Next.js middleware for redirects
βββ drizzle.config.ts # Drizzle ORM configuration
βββ next.config.ts # Next.js configuration
βββ .env # Environment variables
βββ README.md
βββ bun.lock / package.json
git clone https://github.com/RAJVEER42/URL_shortner.git
cd URL_shortnerbun install # or npm installCreate a .env file in the root directory:
MONGO_URI=your_mongodb_connection_string
BASE_URL=http://localhost:3000bun run dev # or npm run devThe app should now be running at http://localhost:3000.
-
The user enters a long URL in the frontend form.
-
The frontend sends a request to the Express backend API.
-
The backend:
- Validates the URL.
- Generates a unique short code.
- Saves the mapping to MongoDB via Drizzle ORM.
-
When a user visits the short link, they are redirected to the original URL.
-
Analytics are optionally logged for each visit.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/shorten |
Create a new shortened URL |
GET |
/api/:shortId |
Redirect to the original URL |
GET |
/api/urls |
Fetch all shortened URLs |
Example:
POST /api/shorten
Content-Type: application/json
{
"url": "https://example.com"
}Response:
{
"shortUrl": "https://short.ly/abc123"
}| Command | Description |
|---|---|
bun run dev |
Run the development server |
bun run build |
Build for production |
bun run start |
Start production server |
bun run lint |
Lint the codebase |
- Built using TypeScript for end-to-end type safety
- Drizzle ORM used for schema management and migrations
- Uses Next.js Middleware for dynamic redirects
- Frontend styling powered by TailwindCSS
- Environment variables managed via
.env
This project is deployed on Orchids Cloud using Bun for fast builds and startup times.
Live Deployment: π URL-SHORTENER
To deploy your own instance:
bun run build
bun run start- Add user authentication (login to manage links)
- Add analytics dashboard with charts
- Support custom short URLs
- QR code generation
- API keyβbased usage limits
Contributions are welcome!
- Fork the repo
- Create a new branch (
feature/awesome-feature) - Commit your changes
- Push to your branch and open a PR
This project is open-source under the MIT License.