Bird
0
0

What does the res.setHeader() method do in a Node.js HTTP server?

easy📝 Conceptual Q1 of 15
Node.js - HTTP Module
What does the res.setHeader() method do in a Node.js HTTP server?
AIt sets a specific HTTP header to be sent in the response
BIt reads headers from the incoming request
CIt closes the HTTP connection immediately
DIt sends the response body to the client
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of res.setHeader()

    This method is used to specify HTTP headers that the server sends back to the client in the response.
  2. Step 2: Differentiate from other response methods

    Unlike methods that send data or close connections, res.setHeader() only sets header information.
  3. Final Answer:

    It sets a specific HTTP header to be sent in the response -> Option A
  4. Quick Check:

    Setting response headers = A [OK]
Quick Trick: Use res.setHeader() to set headers before sending response [OK]
Common Mistakes:
  • Confusing setting headers with sending response body
  • Trying to read request headers with res.setHeader()
  • Calling res.setHeader() after response is sent

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes