title: getting Error: getaddrinfo ENOTFOUND while performing rest api call in node.js using http.request
body: <p>i have created api in node.js which consume set of api hosted at <a href="http://dev.abc.co.in:20081" rel="nofollow noreferrer">http://dev.abc.co.in:20081</a> 
  not every time but randomly sometimes it throws the error</p>
  
  <pre><code>Error: getaddrinfo ENOTFOUND dev.abc.co.in
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
    errno: 'ENOTFOUND',
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'dev.abc.co.in'
  }
  </code></pre>
  
  <p>to call those api i have used request node module because i started getting this error i switched to fetch-node npm module and finally replace the code with internal node module http but getting same error</p>
  
  <p>here is the code i have written using http.request</p>
  
  <pre><code>try{
      const options = {
          hostname: "dev.abc.co.in",
          port : 20081,
          path: "/api/entity/workorder",
          method: Config.method
      };
  
      if(Config.headers){
          options.headers = Config.headers
      }
  
      const req = http.request(options, (res) =&gt; {
  
          let data = '';
          res.on('data', (chunk) =&gt; {
              data += chunk;
          });
          res.on('end', () =&gt; {
  
              callback(res, data);
          });
          req.socket.destroy();
        }).on("error", (err) =&gt; {
          console.log("===Error: ", err);
          callback(null, err);
        });
  
        if(Config.method!="GET" &amp;&amp; Config.body){
          Config.headers["Content-Length"] = Config.body.length;
          req.write(Config.body);
        }
  
        req.end();
      }catch(e){
          console.log("Exception=====",e);
      }
  </code></pre>
  
  <p>as shown in error message issue related to DNS so i try to resolve this DNS using
  node -pe 'require("dns").lookup("dev-vsg.dovertech.co.in",function(){console.dir(arguments)})
  but still not resolved.</p>