Status Codes क्या हैं
Status codes तीन-digit numbers हैं जो client को बताते हैं कि एक request काम किया या नहीं।
In this page:
Syntax
res.status(statusCode).json(body);
res.sendStatus(statusCode);
Status Codes
2xx मतलब success (200 OK, 201 Created, 204 No Content), 3xx redirects, 4xx client mistakes (400, 401, 403, 404), और 5xx server faults (500, 503)।
Accurate codes चुनना clients और tools को सही react करने में मदद करता है। http.STATUS_CODES numbers को names में map करता है।
Note:
http.STATUS_CODES[404] Not Found देता है।
उदाहरण: Status codes
const http = require("http");
for (const code of [200, 201, 204, 301, 400, 401, 403, 404, 500]) {
console.log(code, http.STATUS_CODES[code]);
}
// Output:
// 200 OK
// 201 Created
// 204 No Content
// 301 Moved Permanently
// 400 Bad Request
// 401 Unauthorized
// 403 Forbidden
// 404 Not Found
// 500 Internal Server Error
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- errors के लिए 200 return करना
- 401 और 403 confuse करना
- client mistakes के लिए 500 इस्तेमाल करना
चैप्टर सारांश
- 2xx success दिखाता है, 3xx redirect दिखाता है
- 4xx client error दिखाता है, 5xx server error दिखाता है
- created के लिए 201, empty के लिए 204
- Accurate codes इस्तेमाल करें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: