Skip to content

A full-stack URL shortener built with the MERN stack & TypeScript. Features a modern React + Vite frontend with TailwindCSS and SASS, and a Node.js + Express backend with MongoDB. Efficient, responsive, and user-friendly.

License

Notifications You must be signed in to change notification settings

MartinXCVI/mern-url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MERN URL Shortener

πŸ“„ Introduction

MERN URL Shortener is a full-stack web application that allows users to shorten long URLs efficiently. It is built using the MERN (MongoDB, Express.js, React, Node.js) stack + TypeScript, providing a seamless user experience with a modern frontend and a robust backend API. The application allows users to create, copy, and delete short URLs easily.

πŸ› οΈ Features

Frontend

  • User-Friendly Interface: Built with React, featuring a clean and responsive UI.
  • Shorten URLs: Users can input a long URL and generate a short URL instantly.
  • Copy to Clipboard: Users can copy the generated short URL with a single click.
  • Delete URLs: Users can delete shortened URLs, with a confirmation prompt before deletion.
  • Table View: Displays all the generated short URLs in a structured format.

Backend

  • RESTful API: Built with Node.js and Express.js to handle URL shortening and data management.
  • MongoDB Database: Stores original and shortened URLs efficiently.
  • Validation & Error Handling: Ensures valid URLs are processed and appropriate errors are returned.
  • CORS Support: Allows secure communication between frontend and backend.
  • Environment Variables: Uses .env to store sensitive configuration data.

πŸ—‚οΈ Project Structure

mern-url-shortener/
│── backend/
β”‚   β”œβ”€β”€ dist/
β”‚   β”œβ”€β”€ node_modules/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   β”œβ”€β”€ allowedOrigins.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ corsOptions.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ dbConnection.ts
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ shortUrl.controllers.ts
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   β”œβ”€β”€ ShortUrl.model.ts
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ shortUrl.routes.ts
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”‚   β”œβ”€β”€ validateUrl.ts
β”‚   β”‚   β”œβ”€β”€ server.ts
β”‚   β”œβ”€β”€ .env
β”‚   β”œβ”€β”€ .gitignore
β”‚   β”œβ”€β”€ nodemon.json
β”‚   β”œβ”€β”€ package-lock.json
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tsconfig.json
|
|── frontend/
    β”œβ”€β”€ node_modules/
    β”œβ”€β”€ public/
    β”‚   β”œβ”€β”€ css/
    β”‚   β”œβ”€β”€ sass/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ assets/
    β”‚   β”‚   β”œβ”€β”€ bg.webp
    β”‚   β”‚   β”œβ”€β”€ react.svg
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ Container/Container.tsx
    β”‚   β”‚   β”œβ”€β”€ DataTable/DataTable.tsx
    β”‚   β”‚   β”œβ”€β”€ Footer/Footer.tsx
    β”‚   β”‚   β”œβ”€β”€ Form/Form.tsx
    β”‚   β”‚   β”œβ”€β”€ Header/Header.tsx
    β”‚   β”‚   β”œβ”€β”€ Icons/
    β”‚   β”‚   β”‚   β”œβ”€β”€ CopyIcon.tsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ DeleteIcon.tsx
    β”‚   β”œβ”€β”€ helpers/
    β”‚   β”‚   β”œβ”€β”€ Constants.ts
    β”‚   β”œβ”€β”€ interface/
    β”‚   β”‚   β”œβ”€β”€ UrlData.ts
    β”‚   β”œβ”€β”€ App.tsx
    β”‚   β”œβ”€β”€ index.css
    β”‚   β”œβ”€β”€ main.tsx
    β”‚   β”œβ”€β”€ vite-env.d.ts
    β”œβ”€β”€ .env
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ eslint.config.js
    β”œβ”€β”€ index.html
    β”œβ”€β”€ package-lock.json
    β”œβ”€β”€ package.json
    β”œβ”€β”€ postcss.config.js
    β”œβ”€β”€ readme.md
    β”œβ”€β”€ tailwind.config.js
    β”œβ”€β”€ tsconfig.app.json
    β”œβ”€β”€ tsconfig.json
    β”œβ”€β”€ tsconfig.node.json
    β”œβ”€β”€ vite.config.json

πŸ›°οΈ Technologies Used

Frontend

  • React: UI library for building interactive user interfaces.
  • TypeScript: Allows specifying the types of data being passed around within the code.
  • Vite: Fast development and build tool for modern frontend projects.
  • TailwindCSS: Utility-first CSS framework for styling.
  • SASS: CSS preprocessor for enhanced styling capabilities. A personal preference I have.
  • Axios: HTTP client for making API requests.
  • React Router: Enables routing within the React application.
  • React Icons: Provides a collection of icons for UI enhancements.
  • ESLint: Linter for maintaining clean and consistent TypeScript and JavaScript code.

Backend

  • Node.js: JavaScript runtime for server-side development.
  • TypeScript: Allows specifying the types of data being passed around within the code.
  • Express.js: Minimalist web framework for building web applications.
  • MongoDB: Non-relational document database for agile development.
  • Mongoose: Library used to manage data in MongoDB and Node.js.
  • dotenv: For managing environment variables.
  • Nano ID: To create unique file names or identifiers within the file system.
  • Nodemon: For development convenience with automatic server restarts.

πŸ“‹ Installation

Prerequisites

  • Node.js (latest LTS version)
  • MongoDB (local or cloud instance)

Setup

1. Clone the repository

git clone https://github.com/MartinXCVI/mern-url-shortener.git
cd mern-url-shortener

2. Install dependencies

Backend
cd backend
npm install
Frontend
cd ../frontend
npm install

3. Configure environment variables

Create a .env file in the backend and frontend folders with the required configurations.

Backend

The API requires a MongoDB connection string:

MONGO_URI=mongodb+srv://<username>:<password>@<cluster_name>.mongodb.net/<database_name>?retryWrites=true&w=majority
Frontend

This variable defines the backend API URL

VITE_SERVER_URL=http://localhost:5000/api

4. Run the project

Backend
cd backend
npm start
Frontend
cd ../frontend
npm run dev

πŸ“‘ Documentation Links

πŸ“š Learn More

πŸ“œ License

This project is licensed under the MIT License.

πŸ§‘β€πŸ’» Developer

About

A full-stack URL shortener built with the MERN stack & TypeScript. Features a modern React + Vite frontend with TailwindCSS and SASS, and a Node.js + Express backend with MongoDB. Efficient, responsive, and user-friendly.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published