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.
- 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.
- 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.
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
- 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.
- 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.
- Node.js (latest LTS version)
- MongoDB (local or cloud instance)
git clone https://github.com/MartinXCVI/mern-url-shortener.git
cd mern-url-shortener
cd backend
npm install
cd ../frontend
npm install
Create a .env file in the backend and frontend folders with the required configurations.
The API requires a MongoDB connection string:
MONGO_URI=mongodb+srv://<username>:<password>@<cluster_name>.mongodb.net/<database_name>?retryWrites=true&w=majority
This variable defines the backend API URL
VITE_SERVER_URL=http://localhost:5000/api
cd backend
npm start
cd ../frontend
npm run dev
- Node.js latest documentation
- React official website
- Nodemon project website
- Dotenv repository
- Vite guides
- Getting started with Express.js
- TailwindCSS installation guides
- SASS documentation
- Dotenv repository
- MongoDB documentation
- Mongoose documentation
- Axios documentation
- React Router NPM package
- Nano ID NPM package page
- React Icons repository
This project is licensed under the MIT License.