A RESTful API backend service for a quiz application built with Node.js, Express, and MongoDB. This service handles quiz questions, subjects, chapters, and tracks incorrect answers for review.
- Subject Management: Create, read, update, and delete quiz subjects
- Question Management: Store and retrieve quiz questions with multiple question types (MCQ, Fill-in-the-blank)
- Chapter Organization: Organize questions by chapters within subjects
- Incorrect Answer Tracking: Keep track of questions answered incorrectly for focused review
- CSV Import: Bulk import questions from CSV files
- Review Statistics: Get detailed statistics on quiz performance
- Wikipedia Integration: Fetch term definitions from Wikipedia for enhanced learning
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- MongoDB (local installation or MongoDB Atlas account)
- npm or yarn package manager
- Clone the repository:
git clone https://github.com/yourusername/quiz-maker-backend.git
cd quiz-maker-backend- Install dependencies:
npm install- Create a
.envfile in the root directory:
cp .env.example .env- Configure your environment variables in
.env:
# For local MongoDB
MONGODB_URI=mongodb://localhost:27017/quiz-maker
# For MongoDB Atlas (replace with your connection string)
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/quiz-maker?retryWrites=true&w=majority
# Server port
PORT=5005- Start the server:
node server.jsThe server will start running on http://localhost:5005 (or your configured port).
GET /api/subjects- Get all subjects with question countsGET /api/subjects/:subjectId- Get a specific subjectPUT /api/subjects/:id- Update a subject nameDELETE /api/subjects/:id- Delete a subject and its questions
GET /api/questions?subjectId=XXX&chapter=YYY- Get questions (filtered by subject and optional chapters)GET /api/subjects/:subjectId/chapters- Get all chapters for a subject
POST /api/incorrects- Mark a question as incorrectly answeredGET /api/incorrects?subjectId=XXX&chapters=YYY,ZZZ- Get incorrect questionsDELETE /api/incorrects- Remove a question from incorrect list
GET /api/review-stats- Get comprehensive review statistics
POST /api/upload-csv- Upload CSV file to import questionsGET /api/wikipedia/:word- Fetch Wikipedia definition for a term
To import questions via CSV, use the following format:
| Column | Description | Required | Example |
|---|---|---|---|
| subject | Subject identifier | Yes | MATH101 |
| chapter | Chapter name | Yes | Chapter 1 |
| questionType | Type of question (MCQ/FIB) | No | MCQ |
| question | Question text | Yes | What is 2+2? |
| option_1 to option_6 | Answer options | For MCQ | 3, 4, 5, 6 |
| answer | Correct answer(s) | Yes | 2 |
| explanation | Answer explanation | No | Basic addition |
{
id: String, // Unique identifier
name: String // Display name
}{
subjectId: String,
questionId: Number,
chapter: String,
questionType: String, // "MCQ" or "FIB"
questionText: String,
options: Object, // For MCQ questions
answer: Array, // Correct answer(s)
explanation: String
}{
subjectId: String,
questionId: Number,
chapter: String
}quiz-maker-backend/
├── models/ # MongoDB schema definitions
│ ├── index.js
│ ├── question.js
│ ├── subject.js
│ └── incorrect.js
├── uploads/ # Temporary CSV upload directory
├── server.js # Main application file
├── .env.example # Environment variables template
└── package.json # Project dependencies
The API returns appropriate HTTP status codes:
200- Success400- Bad Request404- Not Found500- Internal Server Error
Error responses include a JSON object with an error field describing the issue.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
If you encounter any problems or have suggestions, please open an issue on GitHub.
- Built with Express.js
- Database powered by MongoDB
- CSV parsing by csv-parser