Bird
0
0

What is the purpose of calling res.end() in a Node.js server when routing requests manually?

easy📝 Conceptual Q2 of 15
Node.js - HTTP Module
What is the purpose of calling res.end() in a Node.js server when routing requests manually?
ATo start listening for new requests
BTo send the response and close the connection
CTo parse the request body
DTo set the request headers
Step-by-Step Solution
Solution:
  1. Step 1: Understand res.end() role

    The res.end() method signals that the response is complete and sends it to the client.
  2. Step 2: Recognize its effect on connection

    Calling res.end() also closes the connection for that request, so no more data can be sent.
  3. Final Answer:

    To send the response and close the connection -> Option B
  4. Quick Check:

    res.end() = Send response and close [OK]
Quick Trick: Always call res.end() to finish response [OK]
Common Mistakes:
  • Forgetting to call res.end() causes hanging requests
  • Using res.end() before writing response data
  • Confusing res.end() with res.write()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes