Before setting up the Quiz Platform, make sure you have the following installed:
- Node.js (v14 or higher)
- npm or yarn
- MongoDB (local installation or MongoDB Atlas account)
npm installcd client
npm install
cd ..Create a .env file in the root directory with the following variables:
NODE_ENV=development
PORT=5000
MONGODB_URI=mongodb://localhost:27017/quiz-platform
JWT_SECRET=your-super-secret-jwt-key-change-this-in-productionMake sure MongoDB is running on your system:
Local MongoDB:
# Start MongoDB service
mongodMongoDB Atlas:
- Create a free account at MongoDB Atlas
- Create a new cluster
- Get your connection string and update the
MONGODB_URIin your.envfile
Development Mode (Both Frontend and Backend):
npm run devBackend Only:
npm run serverFrontend Only:
cd client
npm start- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
To create an admin user, you can either:
-
Register normally and update the database:
// In MongoDB shell or MongoDB Compass db.users.updateOne( { email: "your-email@example.com" }, { $set: { role: "admin" } } )
-
Or modify the registration route temporarily to create an admin user
- User authentication (register, login, JWT)
- User management and profiles
- Quiz CRUD operations
- Score tracking and analytics
- Admin routes and middleware
- Database models and relationships
- API endpoints for all features
- User authentication pages (login/register)
- Navigation and layout
- Home page with features
- Dashboard with statistics
- Quiz listing with search/filter
- Placeholder pages for remaining features
- Responsive design with Tailwind CSS
- Quiz taking interface
- Quiz creation form
- Profile management
- Score history and analytics
- Admin dashboard functionality
- Quiz detail pages
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/user- Get current userPUT /api/auth/profile- Update profile
GET /api/quiz- Get all public quizzesGET /api/quiz/:id- Get specific quizPOST /api/quiz- Create new quizPUT /api/quiz/:id- Update quizDELETE /api/quiz/:id- Delete quizPOST /api/quiz/:id/submit- Submit quiz answersGET /api/quiz/:id/leaderboard- Get quiz leaderboard
GET /api/score/history- Get user's quiz historyGET /api/score/:quizId- Get specific quiz scoreGET /api/score/stats/overview- Get user statisticsGET /api/score/stats/category/:category- Get category statistics
GET /api/user/profile- Get user profilePUT /api/user/profile- Update user profileGET /api/user/quizzes- Get user's created quizzesGET /api/user/dashboard- Get user dashboard data
GET /api/user/admin/users- Get all usersPUT /api/user/admin/users/:id/role- Update user roleGET /api/user/admin/stats- Get admin statistics
quiz_app/
├── models/ # Database models (User, Quiz, Score)
├── routes/ # API routes (auth, quiz, score, user)
├── middleware/ # Custom middleware (auth, admin)
├── client/ # React frontend
│ ├── src/
│ │ ├── components/ # Reusable components
│ │ ├── pages/ # Page components
│ │ ├── contexts/ # React contexts
│ │ └── ...
├── server.js # Express server
├── package.json # Backend dependencies
└── README.md # Documentation
-
MongoDB Connection Error:
- Ensure MongoDB is running
- Check your connection string in
.env - Verify network access if using MongoDB Atlas
-
Port Already in Use:
- Change the PORT in
.envfile - Kill processes using the default ports
- Change the PORT in
-
Module Not Found Errors:
- Run
npm installin both root and client directories - Clear node_modules and reinstall if needed
- Run
-
CORS Issues:
- The backend is configured with CORS for development
- Check that the frontend is running on the correct port
- Complete the quiz taking interface
- Implement quiz creation form
- Add profile management features
- Build score history and analytics
- Complete admin dashboard
- Add more advanced features like:
- Quiz sharing and collaboration
- Advanced analytics and reporting
- Mobile responsiveness improvements
- Real-time features
- Email notifications
For issues and questions:
- Check the troubleshooting section
- Review the API documentation
- Check the console for error messages
- Verify all dependencies are installed correctly