1

I am referring to the next article what is "serviceAccountKey.json" referring to in the Firebase device-to-device notifications tutorial

There is one statement written in the index.js file

var serviceAccount = require("path/to/serviceAccountKey.json");

I would like to know what would be the path here when writing the script in the google cloud function web interface.

Do I have to upload the json file on a bucket and then give the bucket reference path?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

1

You should put your serviceAccountKey.json in the same folder as your index.json. Then when you deploy to Cloud Functions, both the code and the key file will be uploaded and you can refer to the JSON from the code with:

var serviceAccount = require("./serviceAccountKey.json");

Note that you may want to consider using the Admin SDK for Firebase Cloud Messaging to send messages these days. This SDK didn't exist when I wrote blog post, but makes the code for sending messages simpler (at the cost of using an extra SDK).

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks a lot Frank, the suggestion helped me to upload the script. As you had rightly mentioned about using Admin SDK, i did few changes to the blog script but i had to comment out the last statement that was calling the function itself to keep listening "listenForNotificationRequests();". With that removed, is there any way that i can keep the function running after the script is uploaded. - Thanks – subhash salian Dec 05 '17 at 03:15