0

I am using node.js 'request' module for making http request. This code worked for the first time. But now it shows some error.

var request = require('request');
request('http://www.google.com', function (error, response, body) {
    if (!error && response.statusCode == 200) {
    console.log(body); 
} else {
    console.log(error);
}
})

Error:

{ [Error: getaddrinfo ENOTFOUND www.google.com]
 code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'www.google.com' }

I cannot understand why this is happening. My internet works fine and I can open google.com in my browser.

1 Answers1

1

It's a DNS issue. You could try explicitly using Google's DNS by doing:

require('dns').setServers(['8.8.8.8','8.8.4.4']);

Then perform your request.

mscdex
  • 104,356
  • 15
  • 192
  • 153