blunrib blunrib - 3 months ago 17x
Javascript Question

Node HTTP resolution

So you can make a node HTTP GET request like so:

var http = require('http');
var options = {
host: '',

var req = http.get(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));

req.on('error', function(e) {
console.log('ERROR: ' + e.message);

I want to see what IP address that
is going to? How does the node HTTP lib determine which IP address to use if a given DNS resolves to multiple IPs?

By multiple IPs i mean something like:

dig +short

Does the node request lib differ?


Your req object should have a connection object on it, which will have the remote address of the server you were connected to.


Of course, you need to wait until you actually have a connection, so I would just use the connect event which has what you need. Untested, but try this:

req.on('connect', (res, socket, head) => {