A beginner full-stack ToDo application built with MongoDB, Express.js, React, and Node.js. The application is deployed with Frontend on Vercel and Backend on Render.
- Frontend (Vercel): https://mern-to-do-app-six.vercel.app
- Backend API (Render): https://mern-todo-app-sdfd.onrender.com/api
- Create, read, update, and delete ToDos
- Mark ToDos as complete/incomplete
- Modern, responsive UI
- Real-time state management with React Context
- RESTful API backend
- Cross-origin resource sharing (CORS) configured
- Environment-based configuration for different deployments
- Node.js (v14 or higher)
- MongoDB Atlas account (for production) or local MongoDB
- npm or yarn package manager
- Vercel account (for frontend deployment)
- Render account (for backend deployment)
Create a .env
file in the root directory with the following content:
MONGODB_URI=mongodb://localhost:27017/todo-app
PORT=5000
FRONTEND_URL=http://localhost:5173
Backend (Render) Environment Variables:
MONGODB_URI=mongodb+srv://username:[email protected]/todoapp?retryWrites=true&w=majority
FRONTEND_URL=https://your-vercel-link.vercel.app
PORT=5000
Frontend (Vercel) Environment Variables:
VITE_API_URL=https://your-render-link.onrender.com/api
Note:
- For local development, make sure MongoDB is running on your local machine
- For production, use MongoDB Atlas and set the environment variables in your deployment platforms
npm install
npm run dev
# Terminal 1 - Backend
npm run server
# Terminal 2 - Frontend
npm run client
ToDo-MERN-App/
βββ src/ # React frontend
β βββ components/ # React components
β βββ services/ # API service functions
β βββ state/ # React Context for state management
β βββ App.jsx
β βββ main.jsx
β βββ index.css
βββ models/ # MongoDB schemas
βββ routes/ # Express.js API routes
βββ server.js # Main server file
βββ package.json # All dependencies
βββ vite.config.js # Vite configuration
βββ .env # Enviroment variables
βββ README.md
GET /api/todos
- Get all ToDosGET /api/todos/:id
- Get a specific ToDoPOST /api/todos
- Create a new ToDoPUT /api/todos/:id
- Update a ToDoDELETE /api/todos/:id
- Delete a ToDo
{
title: String (required),
description: String (optional),
completed: Boolean (default: false),
dueDate: Date (optional),
userId: ObjectId (optional, for future user authentication),
timestamps: true
}
- Node.js - JavaScript runtime
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- CORS - Cross-origin resource sharing
- React - UI library
- Vite - Build tool and dev server
- Axios - HTTP client
- CSS3 - Styling with modern features
The application uses ES6 modules throughout. The frontend is built with Vite for fast development and building.
- Connect your GitHub repository to Vercel
- Set environment variable:
VITE_API_URL=https://your-render-app.onrender.com/api
- Deploy automatically on every push to main branch
- Connect your GitHub repository to Render
- Set environment variables:
MONGODB_URI
: Your MongoDB Atlas connection stringFRONTEND_URL
: Your Vercel frontend URL
- Deploy automatically on every push to main branch
The application includes robust CORS configuration that:
- Allows requests from the deployed Vercel frontend
- Supports local development on different ports
- Includes debug logging for troubleshooting
- Handles preflight OPTIONS requests
-
MongoDB Connection Error:
- Ensure MongoDB Atlas is accessible
- Check your connection string in environment variables
- Verify network access settings in MongoDB Atlas
-
CORS Error (204 CORS missing allow origin):
- Check that
FRONTEND_URL
is set correctly in Render - Verify the frontend URL matches exactly (no trailing slashes)
- Check Render logs for CORS debug information
- Check that
-
API Not Responding:
- Test backend directly:
https://your-render-app.onrender.com/api
- Check Render logs for errors
- Verify environment variables are set
- Test backend directly:
-
Frontend Not Loading Data:
- Check browser console for errors
- Verify
VITE_API_URL
is set correctly in Vercel - Test API endpoints directly
-
Check Backend Logs (Render):
- Go to Render Dashboard β Your Service β Logs
- Look for CORS debug messages
- Check for MongoDB connection errors
-
Check Frontend Console:
- Open browser DevTools (F12)
- Check Console tab for errors
- Check Network tab for failed requests
-
Test API Directly:
- Visit
https://your-render-app.onrender.com/api
(should show API working message) - Visit
https://your-render-app.onrender.com/api/todos
(should show empty array or TODOs)
- Visit
- User authentication and authorization
- ToDo categories and tags
- Due date reminders
- Search and filtering
- Dark mode toggle
- Mobile app (React Native)
- Real-time updates with WebSockets
- File attachments for TODOs
ISC