Skip to content

A full-stack URL shortener built with Express, MongoDB, and Next.js — a project for developers by Maxim Orlov.

Notifications You must be signed in to change notification settings

TheSolom/URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A full-stack URL shortening service built with Express.js, MongoDB, and Next.js. This project is part of Maxim Orlov's backend projects collection for developers to practice their skills and build portfolio projects.

URL Shortener

🚀 Features

  • Shorten URLs: Convert long URLs into short, manageable links
  • Redirection: Navigate to short URLs to be redirected to original destinations
  • Visit Tracking: Automatically counts visits for each shortened URL
  • Analytics: View visit statistics for any short URL
  • Custom Frontend: Fully functional, pre-built Next.js frontend

🛠️ Tech Stack

  • Backend: Express.js, Node.js
  • Database: MongoDB with Mongoose ODM
  • Frontend: Next.js (pre-built, ready to use)
  • URL Generation: Custom short URL generator with validation

📦 Installation

  1. Clone the repository
git clone <your-repo-url>
cd url-shortener
  1. Install dependencies
# Install backend dependencies
cd backend
npm install

# Install frontend dependencies
cd ../frontend
npm install
  1. Configure environment variables

Create .env files in both backend and frontend directories:

Backend (.env):

NODE_ENV=development
PORT=8000
MONGODB_URI=your_mongodb_connection_string

Frontend (.env):

API_URL=http://localhost:8000
  1. Start the servers

Terminal 1 - Backend:

cd backend
npm start

Terminal 2 - Frontend:

cd frontend
npm start

📋 API Endpoints

Method Endpoint Description
POST /api/url Create a new short URL
GET /api/url/:id Retrieve a short URL (without incrementing the visit count)
GET /api/url/:id/visit Redirect short URL, track visit.

🧪 Testing

The API documentation is provided as an openapi.yaml file. Use the file with tools like:

📁 Project Structure

URL-Shortener/
├── backend/          # Express.js API server
│   ├── controllers/  # Route controllers
│   ├── models/       # MongoDB schemas
│   ├── routes/       # API routes
│   ├── utils/        # Helper functions
│   └── app.js        # Express app
├── frontend/         # Next.js application
└── openapi.yaml      # API documentation

🙏 Acknowledgments


Happy coding!

About

A full-stack URL shortener built with Express, MongoDB, and Next.js — a project for developers by Maxim Orlov.

Topics

Resources

Stars

Watchers

Forks