79082846

Date: 2024-10-13 09:49:09
Score: 0.5
Natty:
Report link
  1. response.status(code):

    • This method sets the HTTP status code for the current response.
    • It does not send the response immediately, but only sets the status code. You still need to call another method, such as response.send(), response.json(), or response.render(), to actually send the response.
    • Example usage: javascript res.status(404).send('Not Found');
  2. response.sendStatus(code):

    • This method combines setting the status code and sending the response with the corresponding text message.
    • It automatically sends the response with the specified HTTP status code and the corresponding text message, which will be used as the response body.
    • Example usage: javascript res.sendStatus(404); // Sends a response with HTTP code 404 and the text "Not Found"

Key differences:

In general, the choice between response.status() and response.sendStatus() depends on your specific situation and how you want to structure your responses.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Igor Peterson