I have downloaded the zip of Firebase real-time database node.js sample
and navigate to the database section
https://github.com/firebase/quickstart-nodejs/tree/master/database
And I located to the line 35
which has the following code
var serviceAccount = require('path/to/serviceAccountKey.json');
But I was wondering where is/what is the serviceAccountKey.json?
in a nutshell, you generate serviceAccountKey. json file by requesting a new private key from the service accounts tab of your settings page in your Firebase dashboard.
Open your browser, go to your Firebase console->Three Dots on the right->Import JSON. Important to note that when importing, whichever node you have selected in your Firebase database will be overwritten, so make sure you don't have your root node selected - create a child node and then do your import.
All Firebase Realtime Database data is stored as JSON objects. You can think of the database as a cloud-hosted JSON tree. Unlike a SQL database, there are no tables or records. When you add data to the JSON tree, it becomes a node in the existing JSON structure with an associated key.
Where is or What is the serviceAccountKey.json is the node js sample of firebase realtime database 1 Reference path for service account key Related 4100 What are the differences between a HashMap and a Hashtable in Java?
Once you create the service account, right click on the three dots and select "create key". It should prompt you with JSON option. Download and store it within your project directory. Share Follow answered Apr 2 '18 at 11:31
in a nutshell, you generate serviceAccountKey.json file by requesting a new private key from the service accounts tab of your settings page in your Firebase dashboard. The returned private key will be a.json file which will be your serviceAccountKey.json file... once you rename it to be serviceAccountKey.json
Securely store the JSON file containing the key. When authorizing via a service account, you have two choices for providing the credentials to your application. You can either set the GOOGLE_APPLICATION_CREDENTIALS environment variable, or you can explicitly pass the path to the service account key in code.
require('path/to/serviceAccountKey.json')
means - call this file to be used in the file you are calling it
serviceAccountKey.json is a file that you have to generate
If you look at this page 'Add Firebase To Your App' https://firebase.google.com/docs/ios/setup under 'Add Firebase to your app' - it says Navigate to the Service Accounts and generate a new private key, doing this will generate what will be your 'serviceAccountKey.json' file after you rename it
place that file in the directory of your choosing local to your cloud code directory, have a look at this comment https://stackoverflow.com/a/42634321/2472466 for more insight into step 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With