Script Valley
Express.js: APIs and Middleware
Express.js Fundamentals/Assessment

Practice & Assessment

Test your understanding of Express.js Fundamentals

Multiple Choice Questions

5
1

What does `res.json()` do differently from `res.send()` when passing an object?

2

What is the correct way to access the `id` in the route `/users/:id`?

3

When you mount a router with `app.use('/api', router)` and the router defines `router.get('/users', ...)`, what is the full path?

4

Which HTTP status code should a POST endpoint return when a resource is successfully created?

5

What is the purpose of calling `app.use(express.json())` near the top of your app?

Coding Challenges

1
1

Build a Books REST API

Create an Express server with a /books endpoint. Support GET /books (return all books), GET /books/:id (return one book by id, 404 if not found), POST /books (create a book with title and author fields, return 201), DELETE /books/:id (remove by id, return 204). Use an in-memory array as the data store. Inputs: JSON body with { title, author } for POST. Outputs: JSON responses with correct status codes. Time estimate: 20-25 minutes.

Easy

Mini Project

1

Notes API — CRUD with Modular Routing

Build a fully modular Notes REST API. Create a notes router in routes/notes.js supporting GET /notes, GET /notes/:id, POST /notes (body: title, content), PUT /notes/:id, and DELETE /notes/:id. Mount it on /api/notes in app.js. Add GET /notes?search=keyword support using req.query to filter notes by title substring. Use an in-memory array. Return appropriate status codes and JSON for all routes. Folder structure must be: app.js, routes/notes.js.

Easy