1. Home
  2. Docs
  3. Web
  4. 5 Minute Quickstart

5 Minute Quickstart

Create an account

The first thing you need to do to get started with Flybase is sign up for a free account.

Once you sign up, create your first app and make a note of your API Key, and the name of your app. We’ll use this URL to store and sync data.

Install Flybase

In the browser

To include the Flybase client library in your website, add a script tag to the <head> section of your HTML file. We recommend including the library directly from our CDN:

<script src="http://cdn.flybase.io/flybase.js"></script>

Node.js Setup

The Flybase JavaScript API and the Flybase Node.js API are exactly the same. Flybase clients run just as easily on your servers as they do on end-user devices. We offer a Node.js module which can be installed via npm from the command line:

$ npm install flybase --save

To use the Flybase Node.js module in your application, just require the Flybase client library.

var Flybase = require("flybase");

Write to your Flybase App

To write data to your Flybase app, we need to first create a reference to it. We do this by passing our Api Key, app name and a collection to our Flybase constructor:

var myDataRef = new Flybase("74k8064f-cd6f-4c07-8baf-b1d241496eec", "web", "data");

A Flybase reference consists of three items:

  1. Your API Key, represented by: 74k8064f-cd6f-4c07-8baf-b1d241496eec
  2. The slug of a Flybase app that has been created in your account: web
  3. Finally, the name of a data collection, in this example: data

Data inside a Flybase app is organized by collections, if you are familiar with SQL tables, then this is similar to tables.

Apps must be created inside your Flybase dashboard, but if you call a collection that does not exist already then it will get created the first time you save data to it.

Once we have a reference to your Flybase app, we can write any valid JSON object to it using set().

Our guide on saving data to Flybase explains the different write methods our API offers and how to know when the data has been successfully written to your Flybase app.

	title: "Hello World!",
	author: "Flybase"

Read from your Flybase App

Data is read from your Flybase app by attaching listeners and handling the resulting events. Assuming we already wrote to myDataRef above, we can retrieve the value by using the on() method:

myDataRef.on("value", function(data) {
	data.forEach( function(snapshot){
		console.log( snapshot.value() );

Data return from a value event can be accessed by calling a .forEach() method and a .value() method to access the document data returned from the callback to access a JSON object.

In the example above, the value event will return the document data. You can learn more about the various event types and how to handle event data in our documentation on reading data.

Was this article helpful to you? Yes 3 No