Updated
A full-stack expense tracker built with MongoDB, Express, React, and Node.js.
This project includes:
server/— Express API with JWT authentication and MongoDBclient/— Vite React app with authentication, transaction management, charts, and dark mode
- 🔐 Email/password signup and login
- ➕ Add income and expense transactions
- 🗑️ Delete transactions
- 🔍 Filter by transaction type (income/expense)
- 📊 Recharts-based pie and bar charts
- 🌙 Dark mode toggle persisted in localStorage
- 💾 Token-based auth stored in localStorage
- 📱 Responsive UI using Tailwind CSS
mern-expense-tracker/
├── server/ # Backend API
│ ├── config/db.js
│ ├── controllers/
│ ├── middleware/auth.js
│ ├── models/
│ ├── routes/
│ ├── .env.example
│ ├── package.json
│ └── server.js
└── client/ # Frontend React app
├── src/
│ ├── api/axios.js
│ ├── components/
│ ├── context/AuthContext.jsx
│ ├── pages/
│ ├── App.jsx
│ └── main.jsx
├── index.html
├── package.json
├── tailwind.config.js
└── vite.config.js
- Node.js 18+ installed
- npm installed
- MongoDB Atlas or MongoDB server URL
- Open terminal and go to the backend folder:
cd server - Copy environment example:
cp .env.example .env
- Update
.envwith your MongoDB connection and JWT secret. - Install dependencies:
npm install
- Start the backend server:
npm run dev
The backend runs at http://localhost:5000 by default.
- Open a new terminal and go to the frontend folder:
cd client - Install dependencies:
npm install
- Run the frontend:
npm run dev
The frontend runs at http://localhost:5173 by default.
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
CLIENT_ORIGIN=http://localhost:5173VITE_API_URL=http://localhost:5000Note:
client/.envis ignored by git via.gitignore, so setVITE_API_URLin your deployment environment.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/signup |
❌ | Create account |
| POST | /api/auth/login |
❌ | Login, returns JWT |
| GET | /api/transactions |
✅ | List user's transactions |
| POST | /api/transactions |
✅ | Add transaction |
| DELETE | /api/transactions/:id |
✅ | Delete transaction |
- Backend: Render, Railway, or Heroku
- Frontend: Vercel, Netlify, or Cloudflare Pages
- Database: MongoDB Atlas
- Deploy from
client/ - Build command:
npm run build - Publish directory:
dist - Set env var:
VITE_API_URL=https://your-backend-url - If using a SPA host, ensure rewrites to
index.htmlfor client-side routing.
- Deploy from
server/ - Start command:
npm start - Set env vars:
MONGO_URIJWT_SECRETCLIENT_ORIGIN=https://your-frontend-urlUpdated V2
401 Unauthorizedon login: make sure the deployed backend has a user created and the correct credentials are used.404on refresh or direct route access: configure your frontend host to rewrite all routes toindex.html.- Wrong API base URL: verify
VITE_API_URLis correctly set in deployment.
- The repository contains both frontend and backend in one monorepo.
- The frontend uses Vite and React Router.
- The backend uses Express, Mongoose, and JWT-based auth.