A full-stack MERN application for shortening URLs with an admin dashboard.
- URL Shortening: Convert long URLs into short, manageable links
- Redirect Service: Automatically redirect short URLs to original destinations
- Admin Dashboard: View all shortened URLs, visit counts, and statistics
- Visit Tracking: Track how many times each short URL has been visited
- Responsive Design: Works on desktop and mobile devices
- Frontend: React + Vite, Tailwind CSS, React Router, Axios
- Backend: Node.js, Express.js, MongoDB, Mongoose
- URL Generation: nanoid for unique short codes
- Node.js (v16 or higher)
- MongoDB (local installation or MongoDB Atlas)
- npm or yarn
# Install frontend dependencies
npm install
# Install backend dependencies
cd backend
npm install
cd ..- Install MongoDB on your system
- Start MongoDB service
- Database will be created automatically at
mongodb://localhost:27017/urlshortener
- Create a free MongoDB Atlas account
- Create a new cluster
- Get your connection string
- Update
backend/.envwith your MongoDB URI
The backend .env file is already configured for local development:
MONGODB_URI=mongodb://localhost:27017/urlshortener
PORT=5000
For production or MongoDB Atlas, update the MONGODB_URI in backend/.env.
cd backend
npm run devBackend will run on http://localhost:5000
# In a new terminal, from the root directory
npm run devFrontend will run on http://localhost:5173
POST /api/shorten- Create a shortened URLGET /api/urls- Get all URLs (for admin page)GET /:shortcode- Redirect to original URLGET /health- Health check
// Shorten a URL
const response = await axios.post('http://localhost:5000/api/shorten', {
original_url: 'https://example.com/very/long/url'
});
// Response
{
"original_url": "https://example.com/very/long/url",
"short_code": "abc123",
"short_url": "http://localhost:5000/abc123",
"created_at": "2024-01-01T00:00:00.000Z"
}- Go to
http://localhost:5173 - Enter a long URL in the input field
- Click "Shorten URL"
- Copy the generated short URL
- Use the short URL to redirect to the original
- Navigate to
http://localhost:5173/admin - View statistics: total URLs, total visits, average visits per URL
- See all shortened URLs in a table format
- Test short URLs directly from the admin panel