Bird
0
0

Identify the error in this Express code snippet:

medium📝 Debug Q6 of 15
Node.js - HTTP Module
Identify the error in this Express code snippet:
app.get('/error', (req, res) => { res.status(400); res.send('Bad Request'); res.status(200); });
ACalling res.send() twice causes error
Bres.status(400) must be called after res.send()
CSetting status 200 after sending response has no effect
DMissing res.end() to finish response
Step-by-Step Solution
Solution:
  1. Step 1: Trace response flow

    res.status(400) sets status, then res.send() sends response with status 400.
  2. Step 2: Analyze res.status(200) after send

    After sending, changing status has no effect because response is finished.
  3. Final Answer:

    Setting status 200 after sending response has no effect -> Option C
  4. Quick Check:

    Change status after send() does nothing [OK]
Quick Trick: Set status before sending response [OK]
Common Mistakes:
  • Trying to change status after send()
  • Expecting multiple sends without error
  • Forgetting response ends after send()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes