This is a full-stack URL shortener application built using the MERN stack (MongoDB, Express.js, React.js, Node.js). It allows users to enter long URLs and receive a shortened version. The backend stores the mapping in MongoDB, and users can be redirected to the original URL via the short code.
- Accepts valid long URLs
- Generates unique 6-character hash-based short URLs
- Stores mappings in a MongoDB database
- Redirects users from short URLs to original URLs
- Responsive and animated React frontend
- React.js
- Axios
- CSS (no frameworks)
- Node.js
- Express.js
- Mongoose
- MongoDB Atlas
- Crypto (for hashing)
url-shortener/
├── backend/
│ ├── index.js
│ ├── .env
│ ├── models/
│ │ └── Url.js
│ └── package.json
│
├── frontend/
│ ├── public/
│ │ └── index.html
│ ├── src/
│ │ ├── App.jsx
│ │ ├── UrlShortener.jsx
│ │ ├── styles.css
│ │ └── index.js
│ └── package.json
git clone https://github.com/your-username/url-shortener.git
cd url-shortenercd backend
npm installCreate a .env file in the backend/ directory and add your MongoDB URI:
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/urlshortenerStart the backend server:
node index.jsThe backend will be available at: http://localhost:5000
cd ../frontend
npm install
npm startThe frontend will be available at: http://localhost:3000
- Open
http://localhost:3000in your browser. - Enter any valid long URL (must include
http://orhttps://). - Click the Shorten button.
- A short URL (e.g.,
http://localhost:5000/u/abc123) will be displayed. - Visiting that short URL will redirect to the original link.
Be sure to securely configure environment variables (MONGO_URI) on your hosting platform.
This project is licensed under the MIT License.