A powerful, secure, and feature-rich link shortening service built for personal and professional use.
π Quick Start β’ β¨ Features β’ π± Demo β’ π API β’ π οΈ Deployment
- π Link Shortening: Create custom or auto-generated short URLs
- π Advanced Analytics: Detailed click tracking with geographic data, device info, and user behavior
- ποΈ Admin Dashboard: Beautiful, responsive web interface for link management
- π Dynamic Updates: Change target URLs without breaking existing short links
- π± QR Code Generation: Built-in QR codes for easy mobile sharing
- π Push Notifications: Optional real-time click notifications via ntfy.sh
- π JWT Authentication: Secure session management
- π‘οΈ CSRF Protection: Cross-site request forgery prevention
- β‘ Rate Limiting: Multi-tier protection against abuse
- π§Ή Input Sanitization: MongoDB injection prevention
- π€ Bot Detection: Automatic filtering of non-human traffic
- π Audit Logging: Comprehensive request logging with Pino
- π REST API: Complete CRUD operations with API key authentication
- π Comprehensive Documentation: Detailed API docs with examples
- β‘ Production Ready: HTTPS redirects, security headers, optimized for deployment
- π§ Environment Configuration: Flexible setup with environment variables
- π± Responsive Design: Bootstrap-based UI that works on all devices
- Node.js (v16+ recommended)
- MongoDB (Atlas or self-hosted)
# Clone the repository
git clone https://github.com/dhivijit/LinkShortner.git
cd LinkShortner
# Install dependencies
npm install
# Create environment file
cp .env.example .env
# Edit .env with your configuration
# Generate admin password hash
node -e "console.log(require('bcrypt').hashSync('your-admin-password', 12))"
# Start the application
npm start # Production
npm run dev # Development (with auto-reload)Create a .env file with the following variables:
# Required
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/linkshortener
ADMIN_PASSWORD_HASH=your-bcrypt-hashed-password
API_KEY=your-secret-api-key
JWT_SECRET=your-jwt-secret-key
CSRF_SECRET=your-csrf-secret
COOKIE_PARSER_SECRET=your-cookie-secret
# Optional
PORT=3000
DOMAIN_URL=yourdomain.com
NTFY_TOPIC=your-ntfy-topic # For push notifications
LOG_LEVEL=info # debug, info, warn, error
NODE_ENV=production # development, productionBeautiful, responsive admin interface with real-time statistics and comprehensive link management
Detailed tracking with geographic data, device information, and visit patterns
- Navigate to
/admin/login - Enter your admin password
- Manage links from the intuitive dashboard
- π Real-time Statistics: Total links, visits, and active links
- π Link Management: Create, edit, delete, and track links
- π Click Analytics: Detailed visitor insights and geographic data
- βοΈ Settings Control: Toggle tracking and notifications per link
- π± QR Codes: Generate QR codes for any short link
- π Quick Actions: Copy links, view stats, manage settings
All API endpoints require authentication using your API key in the Authorization header:
Authorization: your-api-key-hereCreate a short link:
curl -X POST http://localhost:3000/api/links \
-H "Authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{"targetUrl": "https://example.com", "shortened": "example"}'Get all links:
curl -X GET http://localhost:3000/api/links \
-H "Authorization: your-api-key"Update a link:
curl -X PUT http://localhost:3000/api/links/example \
-H "Authorization: your-api-key" \
-H "Content-Type: application/json" \
-d '{"targetUrl": "https://new-example.com"}'π Complete API Documentation: See API_DOCUMENTATION.md for detailed endpoints, examples, and error handling.
- Backend: Node.js + Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT + bcrypt password hashing
- Frontend: EJS templates + Bootstrap 4
- Security: Express Rate Limit, CSRF protection, input sanitization
- Logging: Pino for structured, high-performance logging
- Analytics: Custom tracking with geographic IP resolution
{
shortened: String (unique), // Short code
targetUrl: String, // Destination URL
visitCount: Number, // Total clicks
trackingEnabled: Boolean, // Analytics toggle
notificationEnabled: Boolean, // Push notification toggle
createdAt: Date // Creation timestamp
}{
shortened: String, // Reference to link
targetUrl: String, // Current target
visits: [{ // Array of visit records
visitNumber: Number,
timestamp: Date,
ipAddress: String,
geographic: { country, region, city, coordinates },
userAgent: { browser, os, device, engine },
isBot: Boolean,
referrer: String,
acceptLanguage: String
}]
}- π JWT Authentication: Secure session management with HTTP-only cookies
- π‘οΈ CSRF Protection: Prevents cross-site request forgery attacks
- β‘ Rate Limiting:
- Global: 100 requests/15min per IP
- API: 50 requests/15min per API key
- Auth: 5 attempts/15min per IP
- π§Ή Input Sanitization: MongoDB injection prevention
- π Request Validation: Payload size limits and content validation
- π Production Security: HTTPS enforcement, secure headers
- Encrypted password storage with bcrypt
- Secure cookie configuration
- Environment variable configuration
- Comprehensive error handling
- Structured logging for security monitoring
- Fork this repository
- Connect to Vercel
- Set environment variables in Vercel dashboard
- Deploy automatically
- Clone repository on server
- Set up environment variables
- Use PM2 or similar for process management
- Configure reverse proxy (nginx/Apache)
- Set up SSL certificate
- β Set all required environment variables
- β Configure MongoDB connection
- β Generate secure secrets (API keys, JWT secret)
- β Set up HTTPS in production
- β Configure domain URL
- β (Optional) Set up ntfy.sh for notifications
- πΊοΈ Geographic Data: Country, region, city, coordinates
- π» Device Information: Browser, OS, device type
- π User Behavior: Referrer, language preferences, visit patterns
- π Temporal Data: Visit timestamps, return visitor analysis
- π€ Bot Detection: Automatic filtering of non-human traffic
- βοΈ Tracking Toggle: Enable/disable tracking per link
- π Notification Control: Enable/disable click notifications per link
We welcome contributions! Here's how you can help:
- π Report Bugs: Open an issue with details
- π‘ Feature Requests: Suggest new functionality
- π§ Code Contributions: Fork, branch, code, test, PR
- π Documentation: Improve docs and examples
- π§ͺ Testing: Add tests and improve coverage
# Clone and setup
npm install
npm run dev
This project is licensed under the ISC License.
- π Documentation: Check API_DOCUMENTATION.md
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Email: Create an issue for direct contact
β Star this repository if you find it useful! β
Made with β€οΈ by dhivijit
π Home β’ π Docs β’ π Issues β’ π Releases
