title: Can't determine Firebase Database URL when trying to read Firebase Database from within Node.js Firebase function
body: <p>I am using Flutter to build an app that accesses the Firebase database. All good from the Flutter side....but I am new to Node.js and Cloud Functions. I am trying to create a Node.js function to react to a deletion event of a record on one Firebase Database node and then delete records from two other Firebase Database nodes and image files from Firestore.</p>
  
  <p>I am reacting to the trigger event with a <code>functions.database.onDelete</code> call, no problem, but falling at the very next hurdle i.e.trying to read admin.database to get a snapshot.</p>
  
  <p>I have created a dummy function that uses <code>.onUpdate</code> to pick up a trigger event (don't want to keep having to recreate my data as I would if I used <code>.onDelete</code>) and then tries to read my Firebase Database to access a different node. The trigger event is picked up fine but I don't seem to have a database reference Url to do the read...yet it is the same database. Output on the console log from a call to <code>process.env.FIREBASE_CONFIG</code> shows the Url is present.</p>
  
  <p>The included function code also has commenting to show the various outputs I get on the console log.</p>
  
  <p>I am going crazy over this.....PLEASE can anyone tell me where I am going wrong. Been searching Google, Stackoverflow, Firebase docs for the last two days :-(</p>
  
  <pre class="lang-js prettyprint-override"><code>
  const admin = require("firebase-admin"); // Import Admin SDK
  const functions = require("firebase-functions"); // Import Cloud Functions
  
  admin.initializeApp({
    credential: admin.credential.cert(
      require("./user-guy-firebase-adminsdk.json")
    )
  });
  
  exports.testDeleteFunction = functions.database
    .ref("/user-guys/{userGuyId}")
    // Using .onUpdate as I don't want to keep restoring my data if I use .onDelete
    .onUpdate((snapshot, context) =&gt; {
  
      const userData = snapshot.after.val();
      const userId = userData.userId;
  
      console.log('userId: ' + userId);         // Gives correct console log output: userId: wajzviEcUvPZEcMUbbkPzcw64MB2
  
      console.log(process.env.FIREBASE_CONFIG);
      // Gives correct console log output:
      // {"projectId":"user-guy","databaseURL":"https://user-guy.firebaseio.com","storageBucket":"user-guy.appspot.com","cloudResourceLocation":"us-central"}
  
  
      // I have tried each of the four following calls and received the console log message as indicated after each.
      // 
      // var root = admin.database.ref();       // Console Log Message: TypeError: admin.database.ref is not a function
      // var root = admin.database().ref();     // Console Log Message: Error: Can't determine Firebase Database URL.
      // var root = admin.database.ref;         // Fails at line 31 below with the message indicated.
      // var root = admin.database().ref;       // Console Log Message: Error: Can't determine Firebase Database URL.
  
      console.log(root.toString);               // Console Log Message: TypeError: Cannot read property 'toString' of undefined.
  
      // This is intended to read a chat thread for two users but processing never gets here.
      var database = root.child('chats').child('0cSLt3Sa0FS26QIvOLbin6MFsL43GUPYmmAg9UUlRLnW97jpMCAkEHE3');
  
      database
        .once("value")
        .then(snapshot =&gt; {
          console.log(snapshot.val());
        }, function (errorObject) {
          console.log("The read failed: " + errorObject.code);
        });
      return null; // Will do stuff here once working.
    });
  
  </code></pre>
  
  <p>Error messages shown in code comments.</p>