Practice & Assessment
Test your understanding of Databases, Testing, and Deployment
Multiple Choice Questions
5Why should you export your Express app without calling app.listen() in the module?
What is the primary benefit of using a connection pool when connecting to PostgreSQL?
In a multi-stage Docker build for Node.js, why is the final stage based on the same image but only production files copied?
What does SIGTERM signal to a Node.js process and why should you handle it?
Why should winston logger output JSON in production instead of human-readable text?
Coding Challenges
1Supertest Integration Test Suite
Given an Express app with routes GET /api/items, POST /api/items (body: {name: string, price: number}), GET /api/items/:id, DELETE /api/items/:id, and in-memory array storage, write a Jest and Supertest test suite covering: GET /api/items returns 200 and an array; POST /api/items with valid data returns 201 and the created item; POST /api/items without name returns 400; GET /api/items/:id returns 404 for nonexistent ID; DELETE /api/items/:id returns 204 and the item is gone on subsequent GET. Use beforeEach to reset the in-memory store. Input: the Express app module. Output: all 5 or more tests passing with npm test. Estimated time: 30 minutes.
Mini Project
Production-Ready Notes API
Build and deploy a complete Notes REST API. Stack: Express, Prisma with SQLite, Jest and Supertest, Winston, Docker. Schema: Note {id, title, content, createdAt, updatedAt}. Routes: GET /api/notes, POST /api/notes (validate title min 1 char and content min 1 char with Zod), GET /api/notes/:id, PATCH /api/notes/:id, DELETE /api/notes/:id, GET /health. Middleware: helmet, rate limiter (50 per 15 minutes), request logger with Winston. Testing: write Supertest tests covering success and error paths for every route, minimum 10 tests total. Docker: write a multi-stage Dockerfile and a docker-compose.yml that sets environment variables and mounts a volume for the SQLite database file. Implement SIGTERM graceful shutdown. Deployment: push to GitHub and deploy via Render or Railway using the Dockerfile.
