Bird
0
0

Identify the error in this Express code snippet:

medium📝 Debug Q6 of 15
Rest API - HTTP Status Codes
Identify the error in this Express code snippet:
app.get('/data', (req, res) => {
res.status(200);
res.json({ data: 'info' });
});
AMissing call to end the response after setting status
BNo error, code is correct
CCalling res.status twice
Dres.json cannot be used after res.status
Step-by-Step Solution
Solution:
  1. Step 1: Understand Express response chaining

    res.status sets the status code and returns the response object for chaining.
  2. Step 2: Check usage of res.json after res.status

    Calling res.json after res.status is valid and sends the response with JSON and status.
  3. Final Answer:

    No error, code is correct -> Option B
  4. Quick Check:

    res.status + res.json chaining = C [OK]
Quick Trick: res.status can chain with res.json or res.send [OK]
Common Mistakes:
  • Thinking res.status must be last
  • Believing res.json can't follow res.status
  • Forgetting res.end is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes