Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get ENOTFOUND Node.JS with IP Address

I'm trying get info from a external website, but i get this error:

getaddrinfo ENOTFOUND

My code is:

var options = {
  host: 'http://DOMAIN_OR_IP_ADRESS/',
  port: 8080,
  path: 'PARAMS_GET (I GUESS)',
  method: 'GET',
  agent: false
};

http.get(options, function(resp){
  resp.on('data', function(chunk){
    console.log(chunk);
  });
}).on("error", function(e){
  console.log("Error: http://IP_OR_DOMAIN" + "\n" + e.message);
  console.log( e.stack );
});

When i use this options:

var options = {
      hostname: 'www.google.com',
      port: 80,
      path: '/index.html',
      method: 'GET',
      agent: false
    };

It works well, but not with my domain or IP.

Thanks so much.

like image 703
calbertts Avatar asked Oct 22 '25 06:10

calbertts


1 Answers

I got it!.

It was because I put http:// before the domain or IP address,

Now works with:

var options = {
  host: 'DOMAIN_OR_IP_ADRESS',
  port: 8080,
  path: 'PARAMS_GET (I GUESS)',
  method: 'GET',
  agent: false
};
like image 52
calbertts Avatar answered Oct 23 '25 21:10

calbertts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!