This is a drop-in backend you can give to candidates for the Quiz Maker take-home. It exposes the endpoints from the brief and stores data in a local SQLite file (data.sqlite).
Use node version 20.19.5 to avoid problem in installing dependency
# 1) Install deps
npm i
# 2) Copy env and customize if needed(optional step)
cp .env.example .env
# 3) Initialize DB with schema + sample data
npm run seed
# 4) Start the server
npm run dev # or: npm startBy default the API runs on http://localhost:4000 and requires Authorization: Bearer ${API_TOKEN} on every request.
- Default token (from
.env.example):dev-token - Set your own in
.env→VITE_API_TOKEN=your-secret
Entities
Quiz→{ id, title, description, timeLimitSeconds?, isPublished, createdAt }Question→{ id, quizId, type: 'mcq'|'short'|'code', prompt, options?[], correctAnswer? , position }Attempt→{ id, quizId, startedAt, submittedAt?, answers: Array<{questionId, value}>, score? }
Routes
GET /quizzes→ list quizzes (creator use)POST /quizzes→ createGET /quizzes/:id→ quiz + questions (includescorrectAnswerfor creator views)PATCH /quizzes/:id→ update metadataPOST /quizzes/:id/questions→ create questionPATCH /questions/:id→ update (incl.positionfor reordering)DELETE /questions/:id→ deletePOST /attemptsbody:{ quizId }→ start attempt (returns attempt + sanitized quiz snapshot withoutcorrectAnswer)POST /attempts/:id/answerbody:{ questionId, value }→ upsert answerPOST /attempts/:id/submit→ returns graded result{ score, details: Array<{questionId, correct, expected?}> }
Auto-grading covers MCQ and short; code prompts are not auto-graded and do not affect
score.
- Auth: All routes require
Authorization: Bearer <API_TOKEN>. - Order: Questions are ordered by
position ASC. To reorder,PATCH /questions/:idwith a newposition(simple numeric ordering; collisions are tolerated). - MCQ answers: The taker can send either the selected option index or the option text. The grader accepts both.
- Short answer: Comparison is case-insensitive and whitespace-normalized.
- Code prompts: Stored and returned but not scored.
- Errors: JSON errors with shape
{ error: string }and proper HTTP status codes.
- SQLite file is created at project root (
data.sqlite). - Re-run
npm run seedto reset the sample data. - Feel free to change the CORS origin in
src/server.js.