title: Cloud Functions for Firebase getting value of key
body: <p>I am trying to get the value from author, but it says that it's undefined.</p>
  
  <p>How do I get the value from a specific child from firebase in javascript in Cloud Functions for Firebase, the follwing code should work(?):</p>
  
  <pre><code>const functions = require('firebase-functions');                                          
  
  const admin = require('firebase-admin');                                                  
  
  admin.initializeApp(functions.config().firebase);                                         
  
  exports.sendPushForHelp =                                                                 
  functions.database.ref('/schools/Vittra/alarms/active/{id}').onCreate(event =&gt; {      
      const id = event.params.id;                                                       
      var eventSnapshot = event.data.val();                                             
      var ref = admin.database().ref("/schools/Vittra/alarms/{eventSnapshot}/authorId");
      ref.once('value').then(function(snapshot) {                                       
          var author = snapshot.val();                                                  
      });                                                                               
  
  
  
  
  
  
      const payLoad = {                                                                 
          notification: {                                                               
              title: String(eventSnapshot),                                             
              body: String(author),                                                     
              badge: '1',                                                               
              sound: 'Intruder.mp3'                                                     
          }                                                                             
      };                                                                                
  
  return admin.database().ref('fcmToken').once('value').then(allToken =&gt; {                  
          if (allToken.val()) {                                                             
       const token = Object.keys(allToken.val());                                            
       return admin.messaging().sendToDevice(token, payLoad).then(response =&gt; 
  {              
  
             });                                                                           
  
          };                                                                                
      });                                                                                   
  
  });
  </code></pre>