Courses / Node.js
4. Setting response headers and status codes
Send proper HTTP status codes and response headers using res.writeHead/res.setHeader and res.statusCode.
JavaScript
Setting response headers and status codes
Sending the correct HTTP status and headers tells the client what happened and how to handle the response.
"I need browsers and APIs to know whether my request succeeded and what type of data I'm sending."
Use res.statusCode or res.writeHead to set the numeric HTTP status, and res.setHeader or res.writeHead to send response headers before the body is written.
"I need browsers and APIs to know whether my request succeeded and what type of data I'm sending."
Use res.statusCode or res.writeHead to set the numeric HTTP status, and res.setHeader or res.writeHead to send response headers before the body is written.