title: Cannot read properties of undefined (reading 'statusCode') Nodejs using cheerio
body: <p>am trying to get the title of a webpage for this amusing request and cheerio there am facing this issue  <em><strong>Cannot read properties of undefined (reading 'statusCode')</strong></em> but when I run to try to run separately with the static value it works</p>
  <p>can anyone please help to identify the miskate I have done in my code?</p>
  <p>here is my code</p>
  <pre><code>var request = require(&quot;request&quot;);
  var cheerio = require(&quot;cheerio&quot;);
  
  jsonData = [
    { Domain: &quot;bar-n-ranch.com&quot; },
    { Domain: &quot;barcelona-enabled.com&quot; },
    { Domain: &quot;barefootamelia.com&quot; },
    { Domain: &quot;barmranch.com&quot; },
    { Domain: &quot;barnstablepatriot.com&quot; },
    { Domain: &quot;barrieapartmentrentalsonline.com&quot; },
    { Domain: &quot;basquehomes.com&quot; },
    { Domain: &quot;bassmaster.com&quot; },
    { Domain: &quot;basswoodresort.com&quot; },
  ];
  
  function fetchTitle(url, onComplete = null) {
    request(url, function (error, response, body) {
      var output = url; // default to URL
  
      if (!error &amp;&amp; response.statusCode === 200) {
        var $ = cheerio.load(body);
        console.log(`URL = ${url}`);
  
        var title = $(&quot;head &gt; title&quot;).text().trim();
        console.log(`Title = ${title}`);
  
        output = `[${title}] (${url})`;
      } else {
        console.log(`Error = ${error}, code = ${response.statusCode}`);
      }
  
      console.log(`output = ${output} \n\n`);
  
      if (onComplete) onComplete(output);
    });
  }
  
  jsonData.forEach(function (table) {
    var tableName = table.Domain;
    var URL = &quot;http://&quot; + tableName;
    fetchTitle(URL);
  });
  </code></pre>
  <p>when am passing a value like fetchtitle(&quot;https://www.googlecom&quot;) it works but am getting error when I try to loop JSON data</p>
  <p>error stack trace
  ^</p>
  <pre><code>TypeError: Cannot read properties of undefined (reading 'statusCode')
      at Request._callback (C:\1\naveen\Project\Final\scrap example\test.js:29:56)
      at self.callback (C:\1\naveen\Project\Final\scrap example\node_modules\request\request.js:185:22)
      at Request.emit (node:events:390:28)
      at Request.onRequestError (C:\1\naveen\Project\Final\scrap example\node_modules\request\request.js:877:8)
      at ClientRequest.emit (node:events:390:28)
      at Socket.socketErrorListener (node:_http_client:447:9)
      at Socket.emit (node:events:390:28)
      at emitErrorNT (node:internal/streams/destroy:157:8)
      at emitErrorCloseNT (node:internal/streams/destroy:122:3)
  </code></pre>
  <p>Thank you very much in advance</p>