This is a full-stack online quiz application that allows users to register, log in, and participate in multiple-choice quizzes. Users can view available quizzes, take quizzes, and view their results. This project includes both the frontend (built with React, Vite, and Tailwind CSS) and the backend (built with Node.js, Express, and MongoDB).
You can check the live version of the project here : QuizApp
- User Authentication (Login, Register, Logout)
- Protected routes and sessions management
- Create, view, and participate in multiple-choice quizzes
- Display quiz results and scores
- Responsive design for various devices
- Error handling and notifications
- Node.js and npm installed globally
- MongoDB database (local or remote)
-
Clone the repository:
git clone https://github.com/rd273001/QuizApp.git cd QuizApp
-
Install backend dependencies: Using npm:
npm install
OR Using yarn:yarn
-
Create a .env file in the server folder:
- PORT=5000
- MONGO_URI=mongodb+srv://<your_mongo_uri>
- JWT_SECRET=your_jwt_secret
-
Start the server: Using npm:
npm run dev
OR Using yarn:yarn dev
-
Navigate to the frontend directory:
cd ../client
-
Install frontend dependencies:
npm install
-
Create a .env file in the client folder with the following:
VITE_API_URL=http://localhost:5000
-
Start the frontend development server:
npm run dev
-
Access the application by navigating to http://localhost:3000 in your browser.
- Node.js: Runtime environment for JavaScript.
- Express: Server framework for handling API routes and requests.
- Mongoose: ODM for MongoDB, used to manage data models and interactions with the MongoDB database.
- jsonwebtoken: For creating and verifying JWT tokens, enabling secure sessions for user authentication.
- bcryptjs: Password hashing for securely storing and comparing passwords.
- dotenv: For loading environment variables securely.
- Vite: Fast and lightweight development server for building and serving the frontend application.
- React: Component-based library for building the user interface.
- React Router: Handles navigation and routing between pages.
- TanStack Query: Data-fetching library that manages caching, refetching, and synchronization.
- React Toastify: Provides toast notifications for real-time feedback (e.g., login success, error messages).
- Zod: JavaScript schema validation library used for form validation.
- axios: HTTP client used for making API requests to the backend.
- react-hook-form: Library for managing form state and validation.
- controllers/: Contains logic for handling requests to specific routes (e.g., authController, quizController).
- models/: Defines data models with Mongoose schemas.
- routes/: API route definitions for user authentication, quiz management, etc.
- middleware/: Custom middleware for authorization and error handling.
- src/components/: Reusable UI components such as LoadingIndicator, Header, ProtectedRoute, etc.
- src/context/: Provides context for managing global states like authentication.
- src/pages/: Page components for Home, Login, Register, QuizList, etc.
- src/services/: Contains helper functions for making API requests.
Method | Endpoint | Description |
---|---|---|
POST | /auth/register |
Register new user |
POST | /auth/login |
Log in user |
GET | /auth/restore |
Restore user session |
Method | Endpoint | Description |
---|---|---|
GET | /quiz/all |
Fetch all quizzes |
GET | /quiz/:id |
Fetch quiz details |
POST | /quiz/create |
Create a new quiz |
GET | /quiz/:id/submit |
Submit quiz & fetch quiz results |
- User Registration: New users can sign up, and their details are securely stored in MongoDB.
- Login and Session Management: Users log in, receive a token, and can resume sessions on page refresh.
- Protected Routes: Certain routes (e.g., QuizList, CreateQuiz) are protected and accessible only when logged in.
- Quiz Management: Logged-in users can view available quizzes, create new ones, and view detailed quiz results.
- Session Restore: If a user has an active session (JWT token), they are redirected away from login/register pages.
- Fork the repository
- Create a new branch: git checkout -b feature/YourFeature
- Commit your changes: git commit -m 'New feature added'
- Push to the branch: git push origin feature/YourFeature
- Open a pull request
This project is licensed under the MIT License.