title: Google cloud function returning 204 status when accessing realtime database
body: <p>I have a website for testing purposes hosted via firebase, storing client information on a realtime database which needs to be accessed later. When I do this via a single html document with a script that accesses my reatime database I am able to find information successfuly, but when I copied and pasted that same logic into a cloud function it did not work. I have tried everything I can think of and now when I run the function it executes twice (I am not sure why). The first execution finishes with a http 204 status (no content found). The second execution returns http 500 internal service error. When I checked the logs on firebase it says the error was because "accounts.getValue() is not a function". I think what is happening is on the first execution the function is unable to locate accounts and it executes again without trying to find the accounts, which might be why it can't run accounts.getValue()</p>
  
  <p>I guess my main question is why is my function unable to locate accounts?</p>
  
  <p>geturl is the function I am having trouble with</p>
  
  <p>The structure of my realtime database is 
  database name</p>
  
  <pre><code>-accounts
  
    -some data
  
    -more data
  
    -more account data
  -ActiveQRs
    -some data...
  </code></pre>
  
  <p>My index.js file for cloud functions is </p>
  
  <pre><code>const functions = require('firebase-functions');
  const express = require('express');
  
  const cors = require('cors')({origin: true});
  
  var firebase = require("firebase");
  
  
  var admin = require("firebase-admin");
  
  require("firebase/auth");
  require("firebase/database");
  //require("firebase/firestore");
  //require("firebase/messaging");
  require("firebase/functions");
  
  
  var serviceAccount = require("./serviceKey.json");
  
  
  // Initialize the app with a service account, granting admin 
  //privileges
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://databaseName.firebaseio.com"
  });
  
  const displayqr = express();
  const geturl = express();
  
  
  displayqr.get('/displayqr', (request, response) =&gt; {
      console.log("response sent");
          response.send("testio/qrdisplay.html");
      });
  
  
  
  
   exports.displayqr = functions.https.onRequest(displayqr);
  
  
  
   exports.geturl = functions.https.onCall((email) =&gt; {
  
      const mail = email.toString();
      var result = "";
      result = result + mail;
         var accounts = 
  admin.database().ref("livsuiteform/accounts");
         result = (accounts.getValue());
         accounts.orderByKey().on("value", function(snapshot) {
            snapshot.forEach(function(data) {
              if (data.child("Email").val() == mail) {
                var firstName = data.child("FirstName").val();
                var lastName = data.child("LastName").val();
                result = firstname;
                result = "if loop entered";
                } // end if
           //     return "name not found";
                }); // end for each
            }); // end order by
         return result; 
      });
  </code></pre>