Express.js & REST APIs
Node.js HTTP Status Codes
Status codes tell the client what happened without parsing the body. Using the right one is what lets browsers, caches, monitoring and client libraries behave correctly.
What is HTTP Status Codes in Node.js?
Status codes tell the client what happened without parsing the body. Using the right one is what lets browsers, caches, monitoring and client libraries behave correctly.
Key points to remember
- 401 means "who are you"; 403 means "I know who you are and no".
- Anything in the 4xx range blames the client; 5xx blames the server.
- Include a Retry-After header with a 429 or 503.
The codes an API actually uses
| Code | Meaning | When |
|---|---|---|
| 200 OK | success | GET, PUT, PATCH |
| 201 Created | resource created | POST that creates something |
| 204 No Content | success, empty body | DELETE |
| 400 Bad Request | malformed or invalid input | validation failure |
| 401 Unauthorized | not authenticated | missing or invalid credentials |
| 403 Forbidden | authenticated but not allowed | insufficient permission |
| 404 Not Found | no such resource | unknown id or route |
| 409 Conflict | state conflict | duplicate email on signup |
| 422 Unprocessable | semantically invalid | well-formed but fails business rules |
| 429 Too Many Requests | rate limited | throttling |
| 500 Internal Server Error | unhandled failure | a bug on your side |
| 503 Service Unavailable | temporarily down | maintenance or overload |
Common mistakes with HTTP Status Codes
- Returning 500 for validation errors, which hides real bugs in your monitoring.
- Returning 200 for everything and putting a success flag in the body.
Node.js HTTP Status Codes— Interview Questions & FAQs
What is the difference between 401 and 403?+
401 means the request lacks valid authentication — log in and try again. 403 means you are authenticated but not permitted to do this, so retrying with the same credentials will not help.
