title: List GCP Bucket objects in firebase using nodejs
body: <p>I am trying to get the list of objects from GCP bucket to my app deployed in firebase. The code for it is as follows:</p>
  
  <blockquote>
    <p>apis.js</p>
  </blockquote>
  
  <pre><code>const {Storage} = require('@google-cloud/storage');
  
  const storage = new Storage();
  const bucketName = 'gs://cloud-dev-setup';
  
  exports.getBucketData = (req, res) =&gt; {
      storage.bucket(bucketName).getFiles().then(files =&gt; {
          [files] = files;
          let data = [];
          files.forEach(file =&gt; {
              data.push(file.name);
          });
          res.send(data);
      }).catch( error =&gt; {
          res.send('catch');
      });
  }
  </code></pre>
  
  <blockquote>
    <p>index.js</p>
  </blockquote>
  
  <pre><code>const functions = require('firebase-functions');
  const express = require('express');
  
  const apis = require('./apis');
  const app = express();
  app.get('/test', (req, res) =&gt; {
      res.send("Hello from Firebase!");
  });
  
  app.get('/fileList', apis.getBucketData);
  
  exports.app = functions.https.onRequest(app);
  </code></pre>
  
  <blockquote>
    <p>firebase.json</p>
  </blockquote>
  
  <pre><code>{
    "hosting": {
      "public": "public",
      "rewrites": [{
          "source": "**",
          "function": "app"
      }],
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ]
    }
  }
  </code></pre>
  
  <p>When it is run locally, it gets me the object list and works as expected.</p>
  
  <p>But upon deploying to the firebase server, I get the following error: </p>
  
  <blockquote>
    <p>TypeError: stream.destroy is not a function
        at onResultSet (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/paginator/build/src/index.js:245:24)
        at request (/user_code/node_modules/@google-cloud/storage/build/src/bucket.js:1344:17)
        at Util.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:141:9)
        at retryRequest (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:422:22)
        at onResponse (/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:200:7)
        at /user_code/node_modules/@google-cloud/storage/node_modules/teeny-request/build/src/index.js:222:13
        at process._tickDomainCallback (internal/process/next_tick.js:135:7)</p>
    
    <p>Function execution took 841 ms, finished with status: 'crash'</p>
    
    <p>Error: function crashed out of request scope Function cannot be
    executed.</p>
  </blockquote>
  
  <p>I have been referencing this <a href="https://cloud.google.com/storage/docs/listing-objects#storage-list-objects-nodejs" rel="nofollow noreferrer">GCP page</a> for setting the app.</p>