Bird
0
0

Find the bug in this Express handler:

medium📝 Debug Q7 of 15
Node.js - HTTP Module
Find the bug in this Express handler:
app.get('/json', (req, res) => { res.sendStatus(201); res.json({ success: true }); });
Ares.json() is called after response is sent, so ignored
Bres.sendStatus() does not set status code
Cres.json() must be called before res.sendStatus()
Dres.sendStatus() cannot send status 201
Step-by-Step Solution
Solution:
  1. Step 1: Understand res.sendStatus() behavior

    res.sendStatus(201) sets status and sends response immediately.
  2. Step 2: Check res.json() after send

    Calling res.json() after response is sent has no effect; it is ignored.
  3. Final Answer:

    res.json() is called after response is sent, so ignored -> Option A
  4. Quick Check:

    Response sent once; later sends ignored [OK]
Quick Trick: Send response only once per request [OK]
Common Mistakes:
  • Expecting multiple sends to work
  • Confusing res.sendStatus with res.status
  • Not realizing response ends after sendStatus

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes