Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including iopa-db-firebase with all npm packages installed. Try it out:

var iopaDbFirebase = require("iopa-db-firebase")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

iopa-db-firebase v1.4.9

IOPA Middleware for basic firebase saves, gets and subscribes

IOPA
iopa-db-firebase

NPM NPM NPM

NPM

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 = "xxxx@xxxx-xxx.iam.gserviceaccount.com";
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

API Reference Specification

IOPA

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free