MyInternships.in

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

CodeMeaningWhen
200 OKsuccessGET, PUT, PATCH
201 Createdresource createdPOST that creates something
204 No Contentsuccess, empty bodyDELETE
400 Bad Requestmalformed or invalid inputvalidation failure
401 Unauthorizednot authenticatedmissing or invalid credentials
403 Forbiddenauthenticated but not allowedinsufficient permission
404 Not Foundno such resourceunknown id or route
409 Conflictstate conflictduplicate email on signup
422 Unprocessablesemantically invalidwell-formed but fails business rules
429 Too Many Requestsrate limitedthrottling
500 Internal Server Errorunhandled failurea bug on your side
503 Service Unavailabletemporarily downmaintenance 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.

Related Node.js Topics

Keep learning with these closely related lessons.

Ready to use your Node.js skills?

Find verified Node.js internships and fresher developer jobs across India.

Browse Node.js Internships