A secure, efficient URL Shortening service built using Node.js, Express, MongoDB, and EJS. Supports user authentication, individual URL tracking, and real-time analytics.
- ✅ User Authentication (Sign up & Login)
- 🔐 Only logged-in users can shorten URLs
- ✂️ Generate short URLs from long links
- 🔁 Redirect using short links
- 📈 Click tracking with timestamps (basic analytics)
- 📋 User-specific dashboard (view only your own shortened URLs)
- 🧼 Clean and modular code structure with EJS frontend
- ⚙️ Node.js
- 🚀 Express.js
- 🧠 MongoDB + Mongoose
- ✏️ EJS (templating engine)
- 🧩 shortid (for generating short links)
- 🍪 cookie-parser (for managing sessions)
url-shortener/
├── controllers/
│ ├── url.js # Logic for URL creation and analytics
│ └── user.js # Logic for signup & login
├── models/
│ ├── url.js # URL schema
│ └── user.js # User schema
├── routes/
│ ├── url.js # Routes for URL actions
│ ├── user.js # Routes for signup/login
│ └── staticroute.js # Views like home, login, signup
├── middlewares/
│ └── auth.js # Auth protection middleware
├── service/
│ └── auth.js # Simple in-memory session logic
├── views/
│ ├── home.ejs # Main dashboard
│ ├── login.ejs # Login page
│ └── signup.ejs # Signup page
├── connect.js # MongoDB connection
├── index.js # Main Express server
└── README.md # You're here!git clone https://github.com/Charul192/UrlShortner.git
cd UrlShortnernpm installIn the index.js file, you'll find this line:
connectToMongoDB("<your-host>:<port>/<your-database-name>").then(() => console.log("MongoDB connected"));Replace it with your own MongoDB connection string.
nodemon index.jsServer runs at: http://localhost:8001
Register a new user Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "123456"
}Login existing user Body:
{
"email": "john@example.com",
"password": "123456"
}Create a short URL (only for logged-in users) Body:
{
"url": "https://example.com"
}Response:
{
"id": "short123"
}Redirects to the original URL Example: http://localhost:8001/abc123 → https://www.example.com
Returns number of visits and timestamp logs Example:
{
"totalClicks": 2,
"analytics": [
{ "timestamp": 1719838810201 },
{ "timestamp": 1719838855509 }
]
}- Routes under /url are protected using middleware
- Users can only view their own shortened URLs on the dashboard
- Uses basic cookie-based sessions
🔗 Simple UI to generate and view short URLs
📊 Click count tracking displayed in a clean table layout
- 🔁 Expiry support for short links
- 📊 Graphical analytics (charts for visits)
- 📸 QR code generation
- 📬 Email verification
- 🔐 Password hashing (currently passwords are stored as plain text)
- Made with ❤️ by Charul192
- Feel free to fork, clone, or contribute!