A simple Firebase client for Node.js, based on the firebase gem, by oscardelben.
## Installation
npm install firebase-client
Then, in your project require and instantiate the Firebase client:
var FirebaseClient = require('firebase-client');
var firebase = new FirebaseClient({
url: "https://node-firebase-client.firebaseio.com/",
auth: "my-auth-token"
});
Gets the value of a resource at the specified path. Returns a promise, resolved on a successful HTTP response, or rejected on a client/server error.
firebase.get(path);
To get the "example" resource:
firebase
.get('example')
.then(function(body){
console.log(body);
})
.fail(function(err){
console.log(err);
});
To get all resources withing your Firebase instance:
firebase
.get()
.then(function(body){
console.log(body);
})
.fail(function(err){
console.log(err);
});
Set the value of a resource at the specified path. Returns a promise, resolved on a successful HTTP response, or rejected on a client/server error.
firebase.set(path, data);
firebase
.set('example', { value: true })
.then(function(body){
console.log(body); // returns { value: true }
})
.fail(function(err){
console.log(err);
});
Creates a new child resource under the specified path. Returns a promise, resolved on a successful HTTP response, or rejected on a client/server error.
firebase.push(path, data);
firebase
.push('user', { email: 'test@example.com' })
.then(function(body){
console.log(body); // returns name ref, e.g. { name: "-JR-fhuV6T3vkTNSVrBs" }, of the child resource
})
.fail(function(err){
console.log(err);
});
Updates an existing resource at the specified path. Returns a promise, resolved on a successful HTTP response, or rejected on a client/server error.
firebase.update(path, data);
firebase
.update('example', { value: true })
.then(function(body){
console.log(body); // returns { value: true }
})
.fail(function(err){
console.log(err);
});
Removes resource at specified path. Returns a promise, resolved on a successful HTTP response, or rejected on a client/server error.
firebase.delete(path);
#### Example
firebase
.delete('example')
.then(function(){
console.log(); // returns empty body, i.e. null
})
.fail(function(err){
console.log(err);
});
For more information, check out the Firebase API docs.