Tuesday, 18 April 2017

Node.js writing to Firebase

I have an issue with getting node.js to write to Firebase. I am doing the following in node.js:

var admin = require("firebase-admin");
var serviceAccount = require("./menupool-9e523-firebase-adminsdk-s7908y-23453fc577.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://menupool-9e523.firebaseio.com"
});

// Get a database reference
var db = admin.database();
// creating a starting path in our database
var ref = db.ref("menu-list");

// create a child node of the above path and write the following data to it
var usersRef = ref.child('menu-list');

usersRef.set({
    "Take two new books": {
        completed: true,
        title: "Take two new books",
        user: "test@yahoo.com"
     }
});

This run fine and the script completes but nothing gets written to Firebase!?

I think the issue is here: // creating a starting path in our database var ref = db.ref("menu-list");

What is the database reference that I should be passing?

The Firebase structure is as follows: menupool-9e523 --------menu-list ----------menutitle ---------completed ---------desc ---------user

Any help would be appreciated!!



via iosforme

No comments:

Post a Comment