Module 42: Web Servers with Express

Lesson 4 of 5 · 15–25 minutes

Requests and responses in practice

🏠The everyday picture

A good counter clerk always gives a receipt, says clearly why something was refused, and never shows customers the mess behind the counter.

📘What it really is

{ "error": "Enquiry not found" }
{ "error": "Validation failed", "fields": { "email": "Please enter a valid email." } }

🖱️Try it

Make every route return consistent JSON errors. Add a deliberate throw new Error("boom") in one route and see what the client receives by default (Express sends an HTML error page). You'll fix this properly with an error handler in Module 43.

✅Quick check

A route handler forgets to send a response in one branch. What does the client experience?

Show the answer

The request hangs until it times out.

Why not send the stack trace to the client when something fails?

Show the answer

It reveals internal details that can help attackers, and means nothing to users. Log it instead.

← PreviousRoutes
ProLearners Assist