Bird
0
0

You want to log the client's IP address in a Node.js HTTP server. Which request object property should you use to get the IP address directly?

hard📝 Conceptual Q8 of 15
Node.js - HTTP Module
You want to log the client's IP address in a Node.js HTTP server. Which request object property should you use to get the IP address directly?
Areq.ip
Breq.client.ip
Creq.connection.remoteIP
Dreq.socket.remoteAddress
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to get IP in Node.js core

    In Node.js core HTTP, the IP is available via req.socket.remoteAddress.
  2. Step 2: Check other options

    req.ip is Express-specific; req.connection.remoteIP and req.client.ip do not exist.
  3. Final Answer:

    req.socket.remoteAddress -> Option D
  4. Quick Check:

    Client IP = req.socket.remoteAddress [OK]
Quick Trick: Use req.socket.remoteAddress for client IP in Node.js [OK]
Common Mistakes:
  • Using Express-only req.ip in Node.js core
  • Trying req.connection.remoteIP
  • Assuming req.client.ip exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes