Script Valley
Express.js: APIs and Middleware
Testing and Deploying Express APIs/Assessment

Practice & Assessment

Test your understanding of Testing and Deploying Express APIs

Multiple Choice Questions

5
1

What does Supertest do that a regular HTTP client like Axios cannot in a test environment?

2

Why is it important to set `app.set('trust proxy', 1)` when deploying behind nginx?

3

What is the correct location in app.js to place a global error handler relative to routes?

4

What Swagger/OpenAPI tag tells the UI that an endpoint requires a Bearer JWT token?

5

Why does the `compression()` middleware belong before route definitions in Express?

Coding Challenges

1
1

Write Integration Tests for a CRUD API

Given a provided Express app with GET /items, GET /items/:id, POST /items, PUT /items/:id, DELETE /items/:id routes (in-memory array data store), write a complete Jest + Supertest test suite covering: GET /items returns 200 and array, POST /items with valid body returns 201 with created item, POST /items with missing required field returns 400, GET /items/:id with valid id returns 200, GET /items/:id with non-existent id returns 404, DELETE /items/:id returns 204. Each test should be independent. Inputs: HTTP requests via supertest. Outputs: Jest test file with passing tests. Time estimate: 25 minutes.

Medium

Mini Project

1

Deploy-Ready Express API with Full Test Suite

Build and deploy a complete Bookmarks API. Routes: POST /auth/register, POST /auth/login, GET /bookmarks (auth required), POST /bookmarks (auth, body: url title), DELETE /bookmarks/:id (auth, owner only). Implement: bcryptjs for passwords, JWT auth, global error handler, asyncHandler, consistent response envelope, compression and helmet for production, morgan('combined') in production. Write Jest + Supertest tests covering: register/login flow, 401 on protected routes without token, create and delete bookmark with auth token, 403 on deleting another user's bookmark. Add Swagger docs for all endpoints. Include a /health endpoint. Deploy to Railway or Render with all env vars set via the platform dashboard.

Hard
Practice & Assessment โ€” Testing and Deploying Express APIs โ€” Express.js: APIs and Middleware โ€” Script Valley โ€” Script Valley