url-shortener

πŸ”— URL Shortener

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!

URL Shortener Node.js Express Environment


✨ Features


πŸš€ Quick Start (2-Minute Setup)

🧩 Prerequisites

βš™οΈ Installation & Running

# Navigate to your project folder
cd URL-SHORTENER

# Install dependencies
npm install

# Start the app
npm run dev     # for development
npm start       # for production

🌐 Access Your App

Open http://localhost:3000 in your browser.
πŸŽ‰ You’re live!


πŸ“Έ What You’ll See

🏠 Homepage

πŸ“Š Dashboard

πŸ“ˆ Stats Page


🎯 How to Use

  1. Shorten a URL
    • Paste your long URL β†’ Click β€œShorten” β†’ Copy short link
      Example: http://localhost:3000/abc123
  2. Use Custom Aliases
    • Example:
      http://localhost:3000/my-portfolio
      http://localhost:3000/company-news
  3. Track Analytics
    • Visit /dashboard or /stats/:code to see real-time clicks

πŸ—οΈ Project Structure

URL-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)

πŸ”§ Technical Details

Layer Technology
Backend Node.js + Express.js
Frontend EJS + Vanilla JS
Storage In-memory (simple JS object)
Styling Pure CSS (mobile-first)

πŸ› οΈ API Usage

πŸ”— Shorten a URL

curl -X POST http://localhost:3000/api/url/shorten   -H "Content-Type: application/json"   -d '{"longUrl": "https://example.com/very-long-url"}'

πŸ“Š Get URL Statistics

curl http://localhost:3000/api/url/abc123/stats

🌍 Redirect

Visit:

http://localhost:3000/abc123

πŸš€ Next Steps & Enhancements

βœ… Add MongoDB for persistence
βœ… Implement user authentication
βœ… Generate QR codes for each short link
βœ… Add link expiration and bulk creation
βœ… Export analytics to CSV


❓ FAQ

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.


πŸ› Troubleshooting

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


πŸ“š Learning Resources

This project demonstrates:


🀝 Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Commit your changes
  4. Push and open a PR

πŸ“ž Support

If you’re stuck:


πŸ’– Built With

Perfect for learning full-stack development!