A full-stack web application for shortening URLs with user authentication, analytics tracking, and a modern responsive interface. Built with Node.js, Express, MongoDB, and vanilla JavaScript.
- URL Shortening: Convert long URLs into short, shareable links
- URL Redirection: Automatic redirection to original URLs
- Click Analytics: Track visit history and click counts
- User Authentication: Secure signup, login, and logout
- User Dashboard: Personalized interface for managing URLs
- Responsive Design: Modern, mobile-friendly UI
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcrypt for secure password storage
- CORS Support: Cross-origin resource sharing enabled
- Cookie Management: HTTP-only cookies for security
- Input Validation: Client and server-side validation
- Error Handling: Comprehensive error management
- Docker Support: Containerized deployment
backend/
โโโ controllers/ # Request handlers
โ โโโ auth.controller.js # Authentication logic
โ โโโ url.controller.js # URL management logic
โโโ models/ # Database schemas
โ โโโ user.model.js # User data model
โ โโโ url.model.js # URL data model
โโโ routes/ # API routes
โ โโโ auth.route.js # Authentication endpoints
โ โโโ url.routes.js # URL endpoints
โโโ middlewares/ # Custom middleware
โ โโโ auth.middleware.js # JWT authentication
โโโ lib/ # Utility functions
โ โโโ db.js # Database connection
โ โโโ utlis.js # JWT token utilities
โโโ test/ # Test files
โโโ app.mock.js # Mock data
โโโ url.test.js # URL tests
frontend/
โโโ index.html # Main HTML structure
โโโ script.js # Frontend logic
โโโ style.css # Styling
- Runtime: Node.js 20
- Framework: Express.js 5.1.0
- Database: MongoDB with Mongoose 8.16.1
- Authentication: JWT (jsonwebtoken 9.0.2)
- Password Hashing: bcryptjs 3.0.2
- URL Generation: nanoid 5.1.5
- Testing: Supertest 7.1.3
- Language: Vanilla JavaScript (ES6+)
- Styling: CSS3 with modern features
- HTTP Client: Fetch API
- UI: Responsive design with modern UX
- Containerization: Docker
- Orchestration: Docker Compose
- Web Server: Nginx (for frontend)
- Node.js (v20 or higher)
- MongoDB (local or cloud instance)
- Docker & Docker Compose (optional)
-
Clone the repository
git clone <repository-url> cd url
-
Install dependencies
# Install root dependencies npm install # Install backend dependencies cd backend npm install cd ..
-
Environment Setup Create a
.envfile in the backend directory:PORT=3001 MONGODB_URI=mongodb://localhost:27017/urlshortener JWT_SECRET=your-super-secret-jwt-key NODE_ENV=development
-
Start MongoDB
# Using MongoDB service sudo systemctl start mongod # Or using Docker docker run -d -p 27017:27017 --name mongodb mongo:latest
-
Run the application
# Start backend server cd backend npm start # In another terminal, serve frontend # Using Python (if available) cd frontend python -m http.server 5500 # Or using Node.js serve npx serve frontend -p 5500
-
Clone and navigate to project
git clone <repository-url> cd url
-
Create environment file
# Create .env file in backend directory echo "PORT=3001 MONGODB_URI=mongodb://mongodb:27017/urlshortener JWT_SECRET=your-super-secret-jwt-key NODE_ENV=production" > backend/.env
-
Start with Docker Compose
docker-compose up --build
POST /auth/signup- User registrationPOST /auth/login- User loginPOST /auth/logout- User logoutGET /auth/check- Check authentication status
POST /new- Create short URLGET /:shortId- Redirect to original URLGET /analytics/:shortId- Get URL analytics
POST /new
Content-Type: application/json
{
"url": "https://example.com/very-long-url"
}Response:
{
"id": "abc12345",
"shortUrl": "http://localhost:3001/abc12345",
"originalUrl": "https://example.com/very-long-url"
}POST /auth/signup
Content-Type: application/json
{
"fullName": "John Doe",
"email": "john@example.com",
"password": "password123"
}- Home: URL shortening interface
- Login: User authentication
- Signup: User registration
- Dashboard: User's URL management (placeholder)
- Real-time URL validation
- One-click URL copying
- Responsive notifications
- Session management
- Form validation
Run the test suite:
cd backend
npm test- Base Image: node:20-alpine
- Port: 3001
- Dependencies: Auto-installed from package.json
- Base Image: nginx:alpine
- Port: 80 (mapped to 5500)
- Static Files: Served via Nginx
PORT: Backend server port (default: 3001)MONGODB_URI: MongoDB connection stringJWT_SECRET: Secret key for JWT tokensNODE_ENV: Environment (development/production)
- Origin: http://localhost:5500
- Methods: GET, POST, PUT, DELETE, OPTIONS
- Credentials: Enabled for cookie support
{
email: String (unique, required),
fullName: String (required),
password: String (required, min 6 chars),
timestamps: true
}{
shortId: String (unique, required),
redirectUrl: String (required),
visitHistory: [{
timestamp: Number
}],
timestamps: true
}- Environment Variables: Set secure JWT secrets
- Database: Use MongoDB Atlas or managed database
- HTTPS: Configure SSL certificates
- CORS: Update origins for production domains
- Error Handling: Implement proper logging
- Monitoring: Add health checks and metrics
# Build and run in production mode
docker-compose -f docker-compose.prod.yml up -d- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Siddhesh Kabra
- GitHub: @siddheshkabra
- User-specific URL management
- Custom short URL aliases
- Advanced analytics dashboard
- URL expiration dates
- Bulk URL operations
- API rate limiting
- URL categorization
- QR code generation
- Social media integration
- Admin panel
- User-specific URL management is not fully implemented
- Dashboard functionality is placeholder
- No URL deletion functionality
- Limited error handling in some edge cases
For support, email support@quicklink.com or create an issue in the repository.
QuickLink - Making URLs shorter, one click at a time! ๐