Skip to content

jxsonyx/quizelo-backend

Repository files navigation

Quiz App Backend

Backend API for a quiz/testing platform built with Node.js, Express, MongoDB, and Mongoose.

Features

  • User authentication with JWT (sign-up, sign-in, sign-out)
  • Role-aware access (admin, teacher, student)
  • Test creation and publishing
  • Question creation and assignment to tests
  • Student enrollment for private tests
  • Fetch available tests by role

Tech Stack

  • Node.js (ES Modules)
  • Express
  • MongoDB + Mongoose
  • JWT (jsonwebtoken)
  • Password hashing (bcryptjs)

Prerequisites

  • Node.js >=20.19.0 (required by mongoose@9.x)
  • npm
  • MongoDB connection string

Getting Started

  1. Install dependencies:
npm install
  1. Create a .env file in the project root:
PORT=5500
SERVER_URL=http://localhost:5500
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=1d
  1. Start in development mode:
npm run dev
  1. Or run in normal mode:
npm start

The app currently listens on http://localhost:5500.

Scripts

  • npm run dev - run with nodemon
  • npm start - run with node app.js

API Base URL

/api/v1

Authentication

Protected routes require:

Authorization: Bearer <token>

Token is returned from POST /api/v1/auth/sign-in.

Endpoints

Auth

  • POST /api/v1/auth/sign-up - Create a user
  • POST /api/v1/auth/sign-in - Sign in and get JWT token
  • POST /api/v1/auth/sign-out - Sign out (stateless response)

Users

  • GET /api/v1/users - Get all users
  • GET /api/v1/users/:id - Get single user (auth required)
  • PATCH /api/v1/users/update/:id - Update user (auth required)

Tests

  • POST /api/v1/tests/create - Create test (teacher/admin)
  • PATCH /api/v1/tests/:id/publish - Update/publish test (teacher/admin)
  • POST /api/v1/tests/:id/questions - Add question to test (teacher/admin)
  • POST /api/v1/tests/:id/enroll - Enroll student by email (teacher/admin)
  • GET /api/v1/tests/available - Get available tests by role (auth required)

Example Request Bodies

POST /api/v1/auth/sign-up

{
  "firstName": "Jane",
  "lastName": "Doe",
  "email": "jane@example.com",
  "password": "secret123",
  "role": "student"
}

POST /api/v1/auth/sign-in

{
  "email": "jane@example.com",
  "password": "secret123"
}

POST /api/v1/tests/create

{
  "title": "Intro to Biology",
  "description": "Week 1 quiz",
  "duration": 30,
  "visibility": "public",
  "status": "draft",
  "startTime": "2026-03-07T09:00:00.000Z",
  "endTime": "2026-03-07T09:30:00.000Z"
}

POST /api/v1/tests/:id/questions

{
  "testId": "TEST_OBJECT_ID",
  "questionText": "What is 2 + 2?",
  "type": "single",
  "options": [
    { "text": "3", "isCorrect": false },
    { "text": "4", "isCorrect": true }
  ],
  "points": 1
}

Error Response Format

Most errors are returned as:

{
  "success": false,
  "error": "Error message"
}

Project Structure

backend/
  app.js
  config/
  controllers/
  database/
  middleware/
  models/
  routes/

Current Implementation Notes

  • app.js currently uses a hardcoded port (5500) instead of PORT from .env.
  • POST /api/v1/tests/:id/questions reads testId from request body.
  • POST /api/v1/tests/:id/enroll has query/model mismatches that may affect enrollment flow.

License

MIT - see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors