← Back to Node.js Course | Chapter 6: HTTP Module | Lesson 7 of 7

Status Codes क्या हैं

Status codes तीन-digit numbers हैं जो client को बताते हैं कि एक request काम किया या नहीं।

In this page:

  1. Status Codes
Syntax
javascript
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

javascript
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. #}
आम गलतियां
  1. errors के लिए 200 return करना
  2. 401 और 403 confuse करना
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.