A full-stack unit conversion web app built with the MERN stack (MongoDB, Express.js, React, Node.js).
| Layer | Technology | Version |
|---|---|---|
| Frontend | React + Vite | React 18 |
| Backend | Node.js + Express | Node 18+ |
| Database | MongoDB + Mongoose | v8+ |
| Dev Tools | Nodemon | v3+ |
- Convert units across 5 categories: Length, Weight, Temperature, Volume, Speed
- Real-time conversion with 400ms debounce on input change
- Conversion history saved to MongoDB with timestamps
- Delete individual history entries
- Responsive UI with clean table-based history view
- RESTful API with input validation and error handling
- Vite proxy configured — no hardcoded API URLs in frontend
| Category | Units |
|---|---|
| Length | mm, cm, m, km, inch, foot, yard, mile |
| Weight | mg, g, kg, lb, oz, ton |
| Temperature | Celsius, Fahrenheit, Kelvin |
| Volume | ml, l, cup, pint, quart, gallon |
| Speed | m/s, km/h, mph, knot |
Unit_Converter/
├── client/ # React frontend (Vite)
│ ├── index.html
│ ├── vite.config.js
│ ├── package.json
│ └── src/
│ ├── components/
│ │ ├── Converter.jsx # Conversion form with real-time results
│ │ └── History.jsx # History table with delete
│ ├── App.jsx
│ ├── main.jsx
│ └── index.css
├── server/ # Node/Express backend
│ ├── models/
│ │ └── Conversion.js # Mongoose schema
│ ├── routes/
│ │ └── convert.js # API routes + conversion logic
│ ├── .env # Environment variables
│ ├── index.js # Entry point
│ └── package.json
└── README.md
- Node.js v18+
- npm v9+
- MongoDB v6+ (local) or a MongoDB Atlas cluster
git clone https://github.com/Basant1Saini/Unit_Converter.git
cd Unit_ConverterThe server/.env file is pre-configured for local MongoDB:
PORT=5000
MONGO_URI=mongodb://localhost:27017/unit_converterFor MongoDB Atlas, replace MONGO_URI:
MONGO_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/unit_converter# Backend
cd server && npm install
# Frontend
cd ../client && npm install# Start backend (from server/)
npm run dev
# Start frontend (from client/) — in a separate terminal
npm run dev- Frontend:
http://localhost:5173 - Backend:
http://localhost:5000
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/convert | Perform a conversion |
| GET | /api/history | Get last 50 conversions |
| DELETE | /api/history/:id | Delete a history entry |
Request:
{
"category": "Length",
"fromUnit": "km",
"toUnit": "mile",
"value": 10
}Response:
{
"result": 6.213712,
"id": "64f1a2b3c4d5e6f7a8b9c0d1"
}Response:
[
{
"_id": "64f1a2b3c4d5e6f7a8b9c0d1",
"category": "Length",
"fromUnit": "km",
"toUnit": "mile",
"value": 10,
"result": 6.213712,
"createdAt": "2024-01-15T10:30:00.000Z"
}
]| Package | Purpose |
|---|---|
| express | HTTP server & routing |
| mongoose | MongoDB ODM |
| dotenv | Environment variables |
| cors | Cross-origin requests |
| nodemon | Auto-restart on changes |
| Package | Purpose |
|---|---|
| react | UI library |
| axios | HTTP requests to API |
| vite | Dev server & bundler |
| @vitejs/plugin-react | React support for Vite |
| Location | Command | Description |
|---|---|---|
| server/ | npm run dev |
Start with nodemon |
| server/ | npm start |
Start without nodemon |
| client/ | npm run dev |
Start Vite dev server |
| client/ | npm run build |
Production build |
| client/ | npm run preview |
Preview production build |
- MongoDB connection error – Ensure MongoDB is running locally (
mongod) or your Atlas URI is correct inserver/.env - CORS error – Backend has
corsmiddleware enabled; frontend uses Vite proxy (/api→http://localhost:5000) - Port conflict – Change
PORTinserver/.env; Vite proxy inclient/vite.config.jswill need updating too
MIT