This is a RESTful API for managing quizzes, built with Node.js, Express.js, and MongoDB.
- Create a Quiz: Allows users to create quizzes with questions, multiple-choice options, and correct answers.
- Retrieve Active Quiz: Fetches the currently active quiz based on the date and time.
- Get Quiz Result: Retrieves the result of a quiz after it has finished.
- Get All Quizzes: Fetches a list of all quizzes, including those that are upcoming, active, or finished.
- JWT Authentication: Secures the API endpoints.
- Rate Limiting: Limits the number of requests to certain endpoints.
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT (JSON Web Token)
- Clone the repository:
git clone https://github.com/your-username/quiz-app.git
- Navigate to the project directory:
cd quiz-app
- Install dependencies:
- npm i express nodemon bcrypt mongoose jsonwebtoken dotenv express-rate-limit - npm install node-cron
- Set up environment variables in a
.env
file:PORT=8080 MONGO_URI=your_mongodb_connection_string
- Start the server:
npm run server
- POST
/auth/register
- Registers a new user. - POST
/auth/login
- Logs in an existing user.
-
POST
/quizzes
- Creates a new quiz (requires authentication).-
Headers:
Authorization: Bearer <token>
-
Body:
{ "question": "What is the capital of France?", "options": ["Berlin", "Madrid", "Paris", "Rome"], "rightAnswer": 2, "startDate": "2024-08-30T10:00:00Z", "endDate": "2024-09-01T10:10:00Z" }
-
-
GET
/quizzes/active
- Retrieves the currently active quiz. -
GET
/quizzes/:id/result
- Retrieves the result of a specific quiz (requires authentication). -
GET
/quizzes/all
- Retrieves all quizzes (requires authentication).