Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

server for URL shortener app with user authentication using node.js, express.js & EJS

License

Notifications You must be signed in to change notification settings

CoreTech7704/URL-Shortener

Repository files navigation

πŸš€ Advanced URL Shortener β€” v1.5.0

Node.js Β· Express Β· MongoDB Β· EJS Β· Auth Β· Security-Hardened

Using Node.js, Express, and MongoDB, this production-ready URL shortener offers rate limiting, role-based authorization, authentication, and a safe server-rendered dashboard with EJS.

This project goes beyond simple CRUD to show real-world backend engineering techniques.


✨ Highlights

  • πŸ” JWT + Cookie-based Authentication
  • πŸ§‘β€πŸ’» Role-Based Authorization (NORMAL, ADMIN)
  • 🚦 Rate-Limited URL Creation (abuse protection)
  • 🧠 Secure URL Validation (protocol whitelisting)
  • 🧾 Duplicate URL Prevention
  • πŸ“Š Click Analytics (timestamp-based)
  • πŸ›‘οΈ Security Hardened
    • Helmet headers
    • Payload size limits
    • Secure ID generation (nanoid)
    • Zero known npm vulnerabilities
  • 🌐 Server-Side Rendering (EJS)
  • πŸš€ Railway-ready deployment

🧩 Features

  • πŸ”— Shorten long URLs
  • πŸ” Instant redirection
  • πŸ‘€ User authentication (login / signup)
  • πŸ§‘β€πŸ’» User dashboard β€” manage your URLs
  • 🧭 Admin dashboard β€” manage all URLs
  • πŸ—‘οΈ Delete URLs with access control
  • πŸ“ˆ Track visit history (timestamps)
  • πŸ” Protected routes & middleware
  • ⚠️ Graceful error handling (404 / invalid URLs)

πŸ› οΈ Tech Stack

Layer Technology
Backend Node.js
Framework Express.js
Database MongoDB with Mongoose
Authentication JSON Web Token (JWT) + Cookies
Authorization Role-based middleware
View Engine EJS
Security Helmet, Rate Limiting
ID Generation nanoid
Styling Tailwind CSS

πŸ“¦ Project Structure

URL-Shortener/
β”‚
β”œβ”€β”€ controllers/ # Business logic
β”œβ”€β”€ middlewares/ # Auth & role guards
β”œβ”€β”€ models/ # Mongoose schemas
β”œβ”€β”€ public/ # Static assets
β”œβ”€β”€ routes/ # Express routes
β”œβ”€β”€ serviece/ # authentication services
β”œβ”€β”€ views/ # EJS templates
β”œβ”€β”€ connect.js # MongoDB connection
β”œβ”€β”€ index.js # App entry point
β”œβ”€β”€ package.json
└── README.md

βš™οΈ Installation & Setup

1️⃣ Clone the repository

git clone https://github.com/CoreTech7704/URL-Shortener.git
cd URL-Shortener

2️⃣ Install dependencies

npm install

3️⃣ Environment variables Create a .env file in the project root:

PORT=8001
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_256_bit_secret

4️⃣ Start the server

npm start

Visit: http://localhost:8001


πŸ” Security Considerations

This project follows backend security best practices:

  • βœ… Payload size limits (10kb)
  • βœ… Rate limiting on URL creation
  • βœ… Secure, collision-safe ID generation
  • βœ… URL protocol whitelisting (http, https)
  • βœ… Auth & authorization enforced on protected routes
  • βœ… Helmet security headers
  • βœ… Zero known npm audit vulnerabilities

πŸš€ Deployment

The project is ready for Railway deployment. Key requirements:

  • Node.js β‰₯ 18
  • MongoDB Atlas or Railway MongoDB plugin
  • Environment variables configured in Railway dashboard

πŸ‘¨β€πŸ’» Author

CoreTech7704(Sarvam Patel)
GitHub: https://github.com/CoreTech7704


πŸ“„ License

This project is licensed under the MIT License.


Closing Note

Built with a strong emphasis on practical backend engineering, discipline, and real-world security considerations.
A solid foundation not merely a demonstration.

Developed with ❀️, β˜•, and endless curiosity πŸ’‘

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /