Installation & Setup in JavaScript

The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our Android, iOS, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data.


  1. Add and configure the Firebase JavaScript client SDK into your app.

Create a Database

  1. Navigate to the Realtime Database section of the Firebase console. You'll be prompted to select an existing Firebase project. Follow the database creation workflow.

  2. Select a starting mode for your Firebase Security Rules:

    Test mode

    Good for getting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, make sure to review the Understand Firebase Realtime Database Rules section.

    To get started with the web, iOS, or Android SDK, select test mode.

    Locked mode

    Denies all reads and writes from mobile and web clients. Your authenticated application servers can still access your database.

  3. Choose a region for the database. Depending on your choice of region, the database namespace will be of the form <databaseName> or <databaseName>.<region> For more information, see select locations for your project.

  4. Click Done.

When you enable Realtime Database, it also enables the API in the Cloud API Manager.

Configure Realtime Database Rules

The Realtime Database provides a declarative rules language that allows you to define how your data should be structured, how it should be indexed, and when your data can be read from and written to.

Initialize the Realtime Database JavaScript SDK

You must specify your Realtime Database URL when initializing your JavaScript SDK.

You can find your Realtime Database URL in the Realtime Database section of the Firebase console. It will have the form https://<databaseName> (for us-central1 databases) or https://<databaseName>.<region> (for databases in all other locations).

Initialize your SDK using the following code snippet:

  // Set the configuration for your app
  // TODO: Replace with your project's config object
  var config = {
    apiKey: "apiKey",
    authDomain: "",
    // For databases not in the us-central1 location, databaseURL will be of the
    // form https://[databaseName].[region]
    // For example,
    databaseURL: "",
    storageBucket: ""

  // Get a reference to the database service
  var database = firebase.database();

You're ready to start using the Firebase Realtime Database!

Next Steps