Skip to content

jpstevens/firebase-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

firebase-client

Build Status NPM version Downloads/month

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"
});

Example Usage

GET

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);

Example

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

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);

Example

firebase
.set('example', { value: true })
.then(function(body){
  console.log(body); // returns { value: true }
})
.fail(function(err){
  console.log(err);
});

PUSH

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);

Example

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);
});

UPDATE

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);

Example

firebase
.update('example', { value: true })
.then(function(body){
  console.log(body); // returns { value: true }
})
.fail(function(err){
  console.log(err);
});

DELETE

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);
});

More Info

For more information, check out the Firebase API docs.

About

A simple Firebase client for Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published