1.0.2 • Published 6 years ago

nodefire-realtime v1.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

nodefire-realtime

This package will be used for deal with firebase. Currently it helps to insert user defined data into your firebase realtime database. This packag is based on firebase-admin package.

const fcm = require('nodefire-realtime');

//For Initialize Firebase realtime DB
let serviceAccountKey = require("./serviceAccountKey.json");
let dbUrl = "https://<your-project-id>.firebaseio.com";
fcm.init(dbUrl, serviceAccountKey);
  1. Here, serviceAccountKey.json file is collection of various private keys. You have to download from firebase project>settings>Service accounts. After that click on Generate new private key.
  • (optional)After download that file you can rename it to serviceAccountKey.json.
  1. dbUrl is the path of your realtime database.
  • Go to Firebase console.
  • Select your Database project.
  • go to database.
  • You can see the url of your database, copy it.
//For insert
let dbReference = 'data/user/';
let child='school';
let data = {
    name: "John",
    city: 'new york'
}
fcm.insert(data, dbReference, child);

-> dbReference is like structure of your collection. data/user/ will become

data-
    |
     user-
          your collection data will insert here.
  1. child Sometimes we need to store group of data in the perticuler collection, for that you can use this parameter. However this parameter is optional so if there is no need to use child then you can ignore it. As our above example this will store data like this.
data-
    |
    user-
         |
         school-
                Your collection data will insert here. 

here is actual value store in Firebase.

--data--
        |
        user--
              |
              school--
                      name: John
                      city: New York
  1. let data = {} is used to store data to the firebase DB. It is JSON format data.

Final Code:

const fcm = require('nodefire-realtime');

//For Initialize Firebase realtime DB
let serviceAccountKey = require("./serviceAccountKey.json");
let dbUrl = "https://<your-project-id>.firebaseio.com";
fcm.init(dbUrl, serviceAccountKey);

//For insert
let dbReference = 'data/user/';
let child='school';
let data = {
    name: "John",
    city: 'new york'
}
fcm.insert(data, dbReference, child);

This package is complated for insert, and also in development phase. So, if you face any problems, then let me know.