title: Cloud Function Not Working
body: <p>I want to add notifications to an online android chatting app I have made. I am new to cloud functions, so I tried using the code given here <a href="https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html" rel="nofollow noreferrer">https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html</a></p>
  
  <hr>
  
  <p>My index.js file</p>
  
  <pre><code>var firebase = require('firebase-admin');
  var request = require('request');
  
  var API_KEY = "xyz"; // Your Firebase 
  Cloud Messaging Server API key
  
  // Fetch the service account key JSON file contents
  var serviceAccount = require("firebase.json");
  
  // Initialize the app with a service account, granting admin privileges
  firebase.initializeApp({
  credential: firebase.credential.cert(serviceAccount),
    databaseURL: "https://firebaseio.com/"
  });
  ref = firebase.database().ref();
  
  function listenForNotificationRequests() {
  var requests = ref.child('notificationRequests');
  requests.on('child_added', function(requestSnapshot) {
  var request = requestSnapshot.val();
  sendNotificationToUser(
    request.username, 
    request.message,
    function() {
        console.log('notificationrecived, sent and removed- ' + 
  request.username + '  '+ request.message,);
      requestSnapshot.ref.remove();
    }
   );
   }, function(error) {
    console.error(error);
   });
   };
  
   function sendNotificationToUser(username, message, onSuccess) {
   request({
   url: 'https://fcm.googleapis.com/fcm/send',
   method: 'POST',
   headers: {
    'Content-Type' :' application/json',
    'Authorization': 'key='+API_KEY
   },
   body: JSON.stringify({
    notification: {
      title: message
    },
    to : '/topics/'+username
    })
    }, function(error, response, body) {
    if (error) { console.error(error); }
    else if (response.statusCode &gt;= 400) { 
    console.error('HTTP Error: '+response.statusCode+' - ' 
    +response.statusMessage); 
       }
      else {n
      onSuccess();
     }
    }); 
    }
  
    // start listening
    listenForNotificationRequests();
  </code></pre>
  
  <p>I have successfully deployed this code to the server using node.js command line.
  But this does not show up on the console and nor the logs that I added to debug 
  and the code doesn't seem to work. I have done everything given in the link i mentioned. I could use some help on how to fix my code</p>