title: Google Cloud Function request node module 404
body: <p>When i checking my &quot;img&quot; entry on firebase with google cloud function and the request module i get an error but only when i deployed it on local emulator it works.</p>
  <p>Error i get on my cloud logs:</p>
  <pre><code>removeExpiredDocuments
  Exception from a finished function: TypeError: Cannot read properties of undefined (reading 'statusCode')
  </code></pre>
  <p><img src="https://i.stack.imgur.com/gStel.png" alt="enter image description here" />Example URL for 404:<br />
  <a href="https://ch.cat-ret.assets.lidl/catalog5media/ch/article/5104560/third/lg/5104560_01.jpg" rel="nofollow noreferrer">https://ch.cat-ret.assets.lidl/catalog5media/ch/article/5104560/third/lg/5104560_01.jpg</a></p>
  <pre><code>const functions = require(&quot;firebase-functions&quot;);
  const admin = require(&quot;firebase-admin&quot;);
  const requesth = require('request');
  admin.initializeApp();
  
  exports.removeExpiredDocuments = functions.region('europe-west1').runWith({ memory: &quot;256MB&quot; }).pubsub.schedule(&quot;every 1 hours&quot;).onRun(async (context) =&gt; {
      const db = admin.firestore();
  
      const snaps = await db.collection(&quot;products&quot;).get();
      let promises = [];
      snaps.forEach((snap) =&gt; {
          requesth(snap.data().img, function (error, response) {
              functions.logger.info('[img] error: ' + error, { structuredData: true });
              if ((response) &amp;&amp; (response.statusCode) == 404) {
                  promises.push(snap.ref.delete());
                  functions.logger.info('[img] not found ' + snap.data().name, { structuredData: true });
              }
          });
      });
  
      return Promise.all(promises);
  });
  </code></pre>
  <p>I wanna use google cloud function for checking if the &quot;img&quot; entry is statusCode 404 and if its statusCode 404 delete the document.</p>
  <p>#edit new random error without changed anything
  <a href="https://i.stack.imgur.com/5HDvU.png" rel="nofollow noreferrer">#2 Image of random change errors</a></p>