Script Valley
REST API Development: Beginner to Production
Building Your First API with Node.js and Express/Assessment

Practice & Assessment

Test your understanding of Building Your First API with Node.js and Express

Multiple Choice Questions

5
1

What does `app.use(express.json())` do and why must it come before route definitions?

2

In Express, what happens if a middleware function does NOT call next() and does not send a response?

3

How does Express identify a function as error-handling middleware (4-parameter) vs regular middleware (3-parameter)?

4

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?

5

Which folder in a scalable Express project should contain business logic like database queries?

Coding Challenges

1
1

Build 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.

Easy

Mini Project

1

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.

Medium
Practice & Assessment โ€” Building Your First API with Node.js and Express โ€” REST API Development: Beginner to Production โ€” Script Valley โ€” Script Valley