Practice & Assessment
Test your understanding of Building Your First API with Node.js and Express
Multiple Choice Questions
5What does `app.use(express.json())` do and why must it come before route definitions?
In Express, what happens if a middleware function does NOT call next() and does not send a response?
How does Express identify a function as error-handling middleware (4-parameter) vs regular middleware (3-parameter)?
You mount a router with app.use('/api/v1/users', usersRouter). Inside the router, a handler is defined as router.get('/:id', ...). What URL does this handler respond to?
Which folder in a scalable Express project should contain business logic like database queries?
Coding Challenges
1Build a CRUD API for a to-do list using in-memory storage
Build an Express API with full CRUD for a to-do list. Store data in a JavaScript array (no database). Required endpoints: GET /todos (list all, support ?completed=true/false filter), POST /todos (create, body: {title: string}), GET /todos/:id (get one), PATCH /todos/:id (update title or completed status), DELETE /todos/:id (delete). Each to-do must have id, title, completed (boolean), createdAt (ISO timestamp). Return 404 with a JSON error body for unknown IDs. Time estimate: 25 minutes.
Mini Project
Products Inventory REST API
Build a fully structured Express API for a product inventory system. Requirements: Use the routes/controllers/models folder structure. Implement CRUD for /products โ each product has id, name, price (number), stock (integer), category (string). Support GET /products?category=electronics&inStock=true filtering. Return proper status codes for all operations. Add a global request logger middleware that prints method, URL, and response time in milliseconds. Add a 404 handler for unknown routes. Add error-handling middleware. No database โ use an in-memory array. The project must run with npm start and be testable with curl or Postman.
