Bird
0
0

What will the following Express code send to the client?

medium📝 component behavior Q13 of 15
Node.js - HTTP Module
What will the following Express code send to the client?
app.get('/test', (req, res) => {
  res.status(201).send('Created');
});
AA response with status 200 and body 'Created'
BA response with status 201 and body 'Created'
CA response with status 201 and no body
DAn error because send() cannot follow status()
Step-by-Step Solution
Solution:
  1. Step 1: Understand status and send chaining

    res.status(201) sets status code 201 (Created), then send('Created') sends that text as the response body.
  2. Step 2: Confirm behavior of Express response

    Express allows chaining status and send; the response will have status 201 and body 'Created'.
  3. Final Answer:

    A response with status 201 and body 'Created' -> Option B
  4. Quick Check:

    Status 201 + send text = A response with status 201 and body 'Created' [OK]
Quick Trick: status sets code, send sends body; chaining works [OK]
Common Mistakes:
  • Assuming default status 200 is sent
  • Thinking send() clears status
  • Believing chaining status and send causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes