https://github.com/rohit31-ui/quiz-app
A backend API for a Quiz Application that allows creating quizzes, adding questions with multiple options, fetching quizzes and questions, and supports single-choice, multiple-choice, and text-based questions.
https://github.com/rohit31-ui/quiz-app
dotenv expressjs mongodb mongoose nodejs
Last synced: 2 months ago
JSON representation
A backend API for a Quiz Application that allows creating quizzes, adding questions with multiple options, fetching quizzes and questions, and supports single-choice, multiple-choice, and text-based questions.
- Host: GitHub
- URL: https://github.com/rohit31-ui/quiz-app
- Owner: Rohit31-ui
- Created: 2025-09-27T14:31:33.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-30T13:51:06.000Z (9 months ago)
- Last Synced: 2025-10-07T22:56:34.399Z (9 months ago)
- Topics: dotenv, expressjs, mongodb, mongoose, nodejs
- Language: JavaScript
- Homepage:
- Size: 10.4 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ฏ Quiz Application Backend
---
## ๐ Project Description
This is a **simple backend API** for a Quiz Application. It allows you to:
- โ
Create quizzes with a title
- โ
Add questions to quizzes, including multiple options, and mark correct answers
- โ
Fetch all quizzes
- โ
Fetch all questions (with options) for a specific quiz
The API supports:
- **Single-choice questions**
- **Multiple-choice questions**
- **Text-based questions** (with a 300-character limit)
---
## ๐ ๏ธ Setup Instructions (Run Locally)
### 1๏ธโฃ Clone the repository
```bash
git clone
cd Quiz-Application-Backend/server
```
### 2๏ธโฃ Install dependencies
```bash
npm install
```
### 3๏ธโฃ Create `.env` file
Add the following variables in `.env` file:
```env
MONGODB_URL=mongodb://localhost:27017/quiz
PORT=3000
```
### 4๏ธโฃ Start the server
```bash
# Using nodemon
nodemon server.js
# Or using npm script if added
npm run dev
```
**API Base URL:**
```
http://localhost:3000/api
```
---
## ๐ API Endpoints
| Method | Endpoint | Description |
|--------|---------|-------------|
| POST | /api/quizzes | Create a new quiz |
| POST | /api/quizzes/:quizId/questions | Add a question (with options) to a quiz |
| GET | /api/quizzes | Get all quizzes |
| GET | /api/quizzes/:quizId/questions | Get all questions (with options) for a quiz |
---
## ๐งช Running Test Cases
You can test the API using **Postman** or **VS Code REST Client**.
### 1๏ธโฃ Create Quiz
**POST** `/api/quizzes`
**Body:**
```json
{
"title": "JavaScript Basics"
}
```
### 2๏ธโฃ Add Question
**POST** `/api/quizzes/:quizId/questions`
**Body:**
```json
{
"text": "What is the output of 1 + '1' in JavaScript?",
"type": "single",
"options": [
{ "text": "11", "isCorrect": true },
{ "text": "2", "isCorrect": false }
]
}
```
### 3๏ธโฃ Get All Quizzes
**GET** `/api/quizzes`
### 4๏ธโฃ Get Quiz Questions
**GET** `/api/quizzes/:quizId/questions`
---
## ๐ก Assumptions and Design Choices
- **Schemas**: Three separate schemas (`Quiz`, `Question`, `Option`) to keep data normalized
- **Question Types**: Supports `single`, `multiple`, and `text`
- **Option Correctness**: Correct answers stored using `isCorrect` field in `Option`
- **Validation**:
- Single-choice questions must have exactly one correct option
- Multiple-choice questions must have at least one correct option
- Text questions limited to 300 characters
- **Database**: MongoDB (local or cloud instance)
---
## ๐ ๏ธ Tech Stack
- Node.js
- Express.js
- MongoDB
- Mongoose
- dotenv
---
## ๐ GitHub Repository
- [quiz app](https://github.com/Rohit31-ui/Quiz-app.git)
---
## ๐ซ Contact
- **Email:** [rohitlad012@gmail.com](mailto:rohitlad012@gmail.com)
- **LinkedIn:** [https://www.linkedin.com/in/rohit-lad-1550b4259/](https://www.linkedin.com/in/rohit-lad-1550b4259/)