iopa-db-firebase
v1.4.9
Published
IOPA Middleware for basic firebase saves, gets and subscribes
Downloads
16
Maintainers
Readme
iopa-db-firebase
About
This repository contains helper middleware functions for reading and writing to firebase
Using
npm install iopa-db-firebase --save
Server
var DBMiddleware = require('iopa-db-firebase');
// SET THE FOLLOWING IN ENVIRONMENT VARIABLES INSTEAD!
process.env.FIREBASE_CLIENT_EMAIL = "[email protected]";
process.env.FIREBASE_PRIVATE_KEY = "-----BEGIN PR...";
process.env.FIREBASE_DATABASE_URL = "https://xxxxx-xxxx.firebaseio.com";
process.env.FIREBASE_ROOT = "/";
// Use the DBMiddleWare adds a .db object to every context record for remainder of chain
app.use(require(DBMiddleware));
app.use(require(DBMiddleware.filestorage)); // optional
function(context, next){
context.db.put("/demo/item", {
id: "1234",
name: "demo"
});
context.db.get("/demo/item")
.then(function(item){
context.log(item.timestamp);
});
context.db.put("/demo/item", null);
context.db.subscribe("/demo")
.on("value", function(item){
context.log(item.key);
});
}
Browser
var DBMiddleware = require('iopa-db-firebase');
// SET THE FOLLOWING IN ENVIRONMENT VARIABLES INSTEAD!
process.env.BROWSER = true
process.env.FIREBASE_API_KEY" = "THISISMYPRIVATETOKEN"
process.env.FIREBASE_AUTH_DOMAIN" = "xxxxxx.firebaseapp.com"
process.env.FIREBASE_DATABASE_URL" ="https://xxxxx.firebaseio.com"
process.env.FIREBASE_STORAGE_BUCKET" = "xxxxx.appspot.com"
process.env.FIREBASE_MESSAGING_SENDER_ID = "nnnnnnnnnn"
process.env.FIREBASE_ROOT": "/"
// Use the DBMiddleWare adds a .db object to every context record for remainder of chain
app.use(require(DBMiddleware));
function(context, next){
context.db.put("/demo/item", {
id: "1234",
name: "demo"
});
context.db.get("/demo/item")
.then(function(item){
context.log(item.timestamp);
});
context.db.put("/demo/item", null);
context.db.subscribe("/demo", function(item){
context.log(item.key);
});
}
License
Apache-2.0