A simple quiz application with user authentication using the MERN stack (MongoDB, Express.js, React.js, and Node.js). It incorporates full CRUD operations with token-based authentication (JWT).
- Login Authentication: Admin login with error message for invalid credentials and redirection to the dashboard upon successful login.
- Quiz Management: Add, Edit, and Delete quizzes. Quizzes include title, description (optional), and timer.
- Question Management: Add, Edit, and Delete questions for each quiz. All questions are multiple-choice.
- View Quizzes: View all quizzes added to the application.
- View Scores: View scores of all users who attempted a quiz or any particular quiz.
- Dashboard: View all necessary data on the admin dashboard.
- View Quizzes: View all available quizzes added by the admin.
- Attempt Quizzes: Answer questions in quizzes that the user has not attempted. Display an appropriate message if the user has attempted the quiz previously.
- View Scores: View scores after completing a quiz.
- View Attempts: View all previously attempted quizzes and scores.
- Dashboard: View all necessary data on the user dashboard.
- Frontend: React.js
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JSON Web Token (JWT)
- Node.js
- MongoDB
-
Clone the repository:
git clone https://github.com/yourusername/quiz-web-app.git cd quiz-web-app
-
Install backend dependencies:
cd backend npm install
-
Set up environment variables: Create a .env file in the backend directory with the following content:
MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret
-
Start the backend server:
npm run dev
- Install frontend dependencies:
cd ../frontend
npm install
- Start the frontend server:
npm run dev
The application should now be running, with the frontend accessible at http://localhost:5173 and the backend at http://localhost:3000.
POST /api/auth/register: Sign Up User. POST /api/auth/login: Authenticate admin/user and return a JWT token.
GET /api/admin/quizzes: Get all quizzes.
POST /api/admin/quizzes: Add a new quiz.
PUT /api/admin/quizzes/:id: Update a quiz.
DELETE /api/admin/quizzes/:id: Delete a quiz.
GET /api/admin/quizzes/:id/questions: Get all questions for a quiz.
POST /api/admin/quizzes/:id/questions: Add a new question to a quiz.
PUT /api/admin/questions/:id: Update a question.
DELETE /api/admin/questions/:id: Delete a question.
GET /api/admin/scores: Get scores for all users or a particular quiz.
GET /api/quizzes: Get all available quizzes.
POST /api/quizzes/:id/attempt: Attempt a quiz.
GET /api/users/:id/attempts: Get all attempts for a user