A lightweight URL shortening service built using Node.js, Express, MongoDB, and Mongoose.
It generates unique short IDs for long URLs and redirects users efficiently using dynamic routing.
- Node.js
- Express
- MongoDB
- Mongoose
nanoid
- Generate unique short URLs using
nanoid - Store URL mappings in MongoDB
- Dynamic route-based redirection
- Unique constraint enforcement at database level
- Basic error handling for invalid short IDs
- Minimal UI for testing functionality
- User submits a long URL via form
- Backend generates a 6-character short ID
- Mapping is stored in MongoDB
- Visiting
/:shortIDperforms a database lookup - If found -> server responds with HTTP redirect
- If not found -> returns 404 response
GET /→ Serves UIPOST /shorten→ Creates short URLGET /:shortID→ Redirects to original URL
.
├─ config/
├─ controllers/
├─ models/
├─ routes/
├─ index.js
├─ index.html
© 2026 Saptaparno Chakraborty.
All rights reserved.