This is a Node.js server built with Express and SQLite3 that provides a RESTful API for a quiz application with user authentication and role-based access control.
- User registration and authentication with JWT
- Role-based authorization (admin/user)
- CRUD operations for quizzes
- Quiz question and answer management
- User experience points (exp) tracking
- Secure password storage (plaintext in this example - not recommended for production)
POST /register- Register a new userPOST /auth- Authenticate user and get JWT tokenGET /user- Get current user info
GET /Quiz- Get all quizzesGET /Quiz/:id- Get single quiz by IDPOST /Quiz- Create new quizPUT /Quiz/:id- Update quiz by IDDELETE /Quiz/:id- Delete quiz by ID
GET /QuestionsAdmin/:id- Get all questions for a quizPOST /QuizQuestion/:id- Add question to quizPUT /QuizQuestion/:qid- Update questionDELETE /QuizQuestion/:qid- Delete question
GET /AnswersAdmin/:qid- Get all answers for a questionPOST /QuizAnswer/:qid- Add answer to questionPUT /QuizAnswer/:aid- Update answerDELETE /QuizAnswer/:aid- Delete answer
POST /UserExp/:id- Update user's experience points
GET /QuizQustionsForUser/:id- Get all question IDs for a quizGET /QuizQustionForUser/:qid- Get question and answer optionsPOST /QuizAnswerForUser/:aid- Submit answer to question
-
Clone the repository
-
Install dependencies:
npm install express sqlite3 jsonwebtoken
-
Create a SQLite database file
db.dbwith the required tables:user(id, login, password, exp, role)Quiz(Id, Text, Description)Questions(id, qid, question, type)Answers(qid, aid, text, explanation, true, image)
-
Start the server:
node server.js
- Server port can be configured via environment variable
PORT(default: 3000) - JWT secret key is set in
tokenKeyvariable - Database file is
./db.db
Это сервер на Node.js с использованием Express и SQLite3, предоставляющий REST API для системы викторин с аутентификацией пользователей и ролевым доступом.
- Регистрация и аутентификация пользователей с JWT
- Ролевая модель доступа (админ/пользователь)
- CRUD-операции для викторин
- Управление вопросами и ответами
- Система накопления опыта (exp) для пользователей
- Хранение паролей (в открытом виде - не рекомендуется для продакшена)
POST /register- Регистрация нового пользователяPOST /auth- Аутентификация и получение JWT токенаGET /user- Получение информации о текущем пользователе
GET /Quiz- Получить все викториныGET /Quiz/:id- Получить викторину по IDPOST /Quiz- Создать новую викторинуPUT /Quiz/:id- Обновить викторинуDELETE /Quiz/:id- Удалить викторину
GET /QuestionsAdmin/:id- Получить все вопросы викториныPOST /QuizQuestion/:id- Добавить вопрос к викторинеPUT /QuizQuestion/:qid- Обновить вопросDELETE /QuizQuestion/:qid- Удалить вопрос
GET /AnswersAdmin/:qid- Получить все ответы на вопросPOST /QuizAnswer/:qid- Добавить ответ к вопросуPUT /QuizAnswer/:aid- Обновить ответDELETE /QuizAnswer/:aid- Удалить ответ
POST /UserExp/:id- Изменить количество опыта пользователя
GET /QuizQustionsForUser/:id- Получить ID всех вопросов викториныGET /QuizQustionForUser/:qid- Получить вопрос и варианты ответовPOST /QuizAnswerForUser/:aid- Отправить ответ на вопрос
-
Клонируйте репозиторий
-
Установите зависимости:
npm install express sqlite3 jsonwebtoken
-
Создайте файл базы данных SQLite
db.dbс необходимыми таблицами:user(id, login, password, exp, role)Quiz(Id, Text, Description)Questions(id, qid, question, type)Answers(qid, aid, text, explanation, true, image)
-
Запустите сервер:
node server.js
- Порт сервера настраивается через переменную окружения
PORT(по умолчанию: 3000) - Секретный ключ JWT задается в переменной
tokenKey - Файл базы данных:
./db.db