A full-featured, self-hosted URL shortener service with analytics built using Node.js and Express.
Perfect for local development and learning full-stack development!
# Navigate to your project folder
cd URL-SHORTENER
# Install dependencies
npm install
# Start the app
npm run dev # for development
npm start # for production
Open http://localhost:3000 in your browser.
π Youβre live!
http://localhost:3000/abc123http://localhost:3000/my-portfoliohttp://localhost:3000/company-news/dashboard or /stats/:code to see real-time clicksURL-SHORTENER/
βββ server.js # Main server logic
βββ package.json # Dependencies and scripts
βββ .env # Environment variables
βββ views/ # EJS templates
β βββ index.ejs
β βββ dashboard.ejs
β βββ stats.ejs
βββ public/ # Static files (CSS, JS)
| Layer | Technology |
|---|---|
| Backend | Node.js + Express.js |
| Frontend | EJS + Vanilla JS |
| Storage | In-memory (simple JS object) |
| Styling | Pure CSS (mobile-first) |
curl -X POST http://localhost:3000/api/url/shorten -H "Content-Type: application/json" -d '{"longUrl": "https://example.com/very-long-url"}'
curl http://localhost:3000/api/url/abc123/stats
Visit:
http://localhost:3000/abc123
β
Add MongoDB for persistence
β
Implement user authentication
β
Generate QR codes for each short link
β
Add link expiration and bulk creation
β
Export analytics to CSV
Q: Where is my data stored?
A: In memory β resets when the server restarts.
Q: Can I use it in production?
A: For learning and development, yes. For production, add a database.
Q: How do I change the port?
A: Add PORT=8080 in .env or run set PORT=8080.
Port in use?
netstat -ano | findstr :3000
taskkill /PID [PID] /F
Reinstall dependencies
rm -rf node_modules
npm install
Check your Node version (16+) and file structure
This project demonstrates:
If youβre stuck:
Perfect for learning full-stack development!