Error: getaddrinfo ENOTFOUND in nodejs for get call

后端 未结 10 728
离开以前
离开以前 2020-11-30 00:24

I am running a web server on node the code for which is given below

var restify = require(\'restify\');

var server = restify.createServer();

var quotes = [         


        
10条回答
  •  独厮守ぢ
    2020-11-30 00:56

    var http = require('http');
    
      var options = {     
          host: 'localhost',
          port: 80,
          path: '/broadcast'
        };
    
      var requestLoop = setInterval(function(){
    
          http.get (options, function (resp) {
            resp.on('data', function (d) {
              console.log ('data!', d.toString());
            });
            resp.on('end', function (d) {
               console.log ('Finished !');
            });
          }).on('error', function (e) {
              console.log ('error:', e);
          });
      }, 10000);
    
    var dns = require('dns'), cache = {};
    dns._lookup = dns.lookup;
    dns.lookup = function(domain, family, done) {
        if (!done) {
            done = family;
            family = null;
        }
    
        var key = domain+family;
        if (key in cache) {
            var ip = cache[key],
                ipv = ip.indexOf('.') !== -1 ? 4 : 6;
    
            return process.nextTick(function() {
                done(null, ip, ipv);
            });
        }
    
        dns._lookup(domain, family, function(err, ip, ipv) {
            if (err) return done(err);
            cache[key] = ip;
            done(null, ip, ipv);
        });
    };
    
    // Works fine (100%)
    

提交回复
热议问题