Node.js
/Beginner
HTTP Status Codes
Definition
Standardized 3-digit numbers sent by the server to the client indicating the result of an HTTP request.
Explain Like I'm New
It's the server's mood ring. 200s = Happy (Success). 300s = Redirecting (Go over there). 400s = Client Error (YOU messed up, like asking for a page that doesn't exist - 404). 500s = Server Error (I messed up, my database crashed - 500).
Real World Example
If you try to log into Netflix with the wrong password, the backend returns a `401 Unauthorized` status code. The frontend React app sees the 401 code and shows a red 'Wrong Password' error box.
Common Use Cases
- •Communicating success/failure to frontends
- •SEO optimization (Google bots read 301 redirects)
Terminal Output
bash / terminal
// --- COMMON STATUS CODES CHEAT SHEET ---
// 200 OK (Read success)
// 201 Created (POST success, new item made)
// 204 No Content (DELETE success, nothing to return)
// 400 Bad Request (Missing email in JSON body)
// 401 Unauthorized (Invalid JWT token)
// 403 Forbidden (Valid token, but lacks Admin rights)
// 404 Not Found (URL doesn't exist)
// 429 Too Many Requests (Rate limit hit)
// 500 Internal Server Error (Database crash, unhandled exception)
// 503 Service Unavailable (Server is overloaded or undergoing maintenance)
console.log("Always send appropriate status codes! A 200 OK containing an error message is a terrible anti-pattern.");
Interview Questions
basic
- What does status code 200 mean?
intermediate
- What is the difference between 401 and 403?