NodeFire
NodeFire expands the Firebase Admin SDK with the
following features:
- Any paths passed in are treated as templates and interpolated within an implicit or explicit scope, avoiding manual (and error-prone) string concatenation. Characters forbidden by Firebase are automatically escaped.
- Since one-time fetches of a reference are common in server code, a new
get
method makes them easy and an optional LRU cache keeps the most used ones pinned and synced to reduce latency. - Transactions prefetch the current value of the reference to avoid having every transaction re-executed at least twice.
- A
childrenKeys()
method allows you to perform a shallow query to fetch a Reference
's children keys without fetching all of its data. - You have the option of obtaining security rule traces when an operation fails due to permission denied.
If you'd like to be able to use generators as on
or once
callbacks, make sure to set Promise.co
to a co
-compatible function.
Example
const co = require('co');
const admin = require('firebase-admin');
const NodeFire = require('nodefire');
NodeFire.setCacheSize(10);
admin.initializeApp(
);
const db = new NodeFire(admin.database().ref())
co(
(function*() {
var stuff = db.child('stuffs', {
foo: 'bar',
baz: {
qux: 42
}
});
var data = yield {
theFoo: stuff.child('foos/:foo').get(),
theUser: stuff.root.child('users/{baz.qux}').get(),
};
yield [
stuff.child('counters/:foo').transaction((value) => value + 1),
stuff.child('bars/:foo/{theUser.username}', data).set(data.theFoo.bar),
];
})()
);
API
This is reproduced from the source code, which is authoritative.
class NodeFire;
constructor(ref, scope)
static LOG_TRANSACTIONS = false
static SERVER_TIMESTAMP
static enableFirebaseLogging(enable)
enablePermissionDebugging(legacySecret)
static interceptOperations(callback)
static setCacheSize(max)
static setCacheSizeForDisconnectedApp(max)
static getCacheCount()
static getCacheHitRate()
static resetCacheHitRate()
static escape(key)
static unescape(key)
path
key
ref
root
parent
database
interpolate(string, scope)
scope(scope)
child(path, scope)
get()
cache()
uncache()
set(value)
update(value)
remove()
push(value)
transaction(updateFunction, options)
childrenKeys(options)
newKey()
now
isEqual()
toJSON()
toString()
on(eventType, callback, cancelCallback, context)
off(eventType, callback, context)
limitToFirst(limit)
limitToLast(limit)
startAt(value, key)
endAt(value, key)
equalTo(value, key)
orderByChild(path)
orderByKey()
orderByValue()