Installation & Setup in JavaScript Stay organized with collections Save and categorize content based on your preferences.
The Firebase Realtime Database is a cloud-hosted database. Data is stored asJSON and synchronized in realtime to every connected client. When you buildcross-platform apps with our Android, Apple platforms, and JavaScript SDKs, all of yourclients share one Realtime Database instance and automatically receiveupdates with the newest data.
Prerequisites
If you haven't already,install the Firebase JS SDK and initialize Firebase.
Create a Database
Navigate to theRealtime Database section of theFirebase console.You'll be prompted to select an existing Firebase project.Follow the database creation workflow.
Select a starting mode for yourFirebase 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,makesure to review theUnderstand Firebase Realtime Database Rulessection.
- Note: If you create a database in Test mode and make no changes to thedefault world-readable and world-writeableSecurity Rules within a trialperiod, you will be alerted by email, then your database rules willdeny all requests. Note the expiration date during theFirebase consolesetup flow.
To get started with the web, Apple, or Android SDK, select testmode.
- Locked mode
Denies all reads and writes from mobile and web clients.Your authenticated application servers can still access your database.
Choose a location for the database.
Depending on thelocation of the database, theURL for the new database will be in one of the following forms:
(fordatabases inDATABASE_NAME.firebaseio.comus-central1) (for databases in all other locations)DATABASE_NAME.REGION.firebasedatabase.app
ClickDone.
When you enableRealtime Database, it also enables the API in theCloud API Manager.
ConfigureRealtime Database Security Rules
TheRealtime Database provides a declarative rules language that allows you todefine how your data should be structured, how it should be indexed, and whenyour data can be read from and written to.
Note: By default, read and write access to your database is restricted so onlyauthenticated users can read or write data. To get started without setting upAuthentication, you canconfigure your rules for public access. This doesmake your database open to anyone, even people not using your app, so be sureto restrict your database again when you set up authentication.Add theRealtime Database JS SDK and initializeRealtime Database
You must specify yourRealtime Database URL when initializing the JavaScript SDK.
You can find yourRealtime Database URL in theRealtime Database section of theFirebase console. Depending on thelocation of the database, the database URL will be in one of the following forms:
(for databases inhttps://DATABASE_NAME.firebaseio.comus-central1) (for databases in all other locations)https://DATABASE_NAME.REGION.firebasedatabase.app
Initialize the SDK using the following code snippet:
Web
Learn more about thetree-shakeable modular web API andupgrade from the namespaced API.
import{initializeApp}from"firebase/app";import{getDatabase}from"firebase/database";//TODO:Replacethefollowingwithyourapp's Firebase project configuration//See:https://firebase.google.com/docs/web/learn-more#config-objectconstfirebaseConfig={//...//Thevalueof`databaseURL`dependsonthelocationofthedatabasedatabaseURL:"https://DATABASE_NAME.firebaseio.com",};//InitializeFirebaseconstapp=initializeApp(firebaseConfig);//InitializeRealtimeDatabaseandgetareferencetotheserviceconstdatabase=getDatabase(app);
Web
Learn more about thetree-shakeable modular web API andupgrade from the namespaced API.
importfirebasefrom"firebase/app";import"firebase/compat/database";//TODO:Replacethefollowingwithyourapp's Firebase project configuration//See:https://firebase.google.com/docs/web/learn-more#config-objectconstfirebaseConfig={//...//Thevalueof`databaseURL`dependsonthelocationofthedatabasedatabaseURL:"https://DATABASE_NAME.firebaseio.com",};//InitializeFirebasefirebase.initializeApp(firebaseConfig);//InitializeRealtimeDatabaseandgetareferencetotheserviceconstdatabase=firebase.database();
You're ready to start using theFirebase Realtime Database!
Next Steps
Learn how tostructure data forRealtime Database.
Prepare to launch your app:
EnableApp Check to help ensure that only yourapps can access your databases.
Set upbudgetalertsfor your project in theGoogle Cloud console.
Monitor theUsage and billingdashboard in theFirebase console to get an overall picture of your project'susage across multiple Firebase services.You can also visit theRealtime DatabaseUsagedashboard for moredetailed usage information.
Review theFirebase launch checklist.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.