Initialize the Realtime Database JavaScript SDK

    0

    4

    Khalid Khan

    Firebase Smart Code Snippets

    The code initializes an app instance with the firebaseConfig object, which contains the following properties:

    apiKey - The API key for your app authDomain - The domain for your app's authentication databaseURL - The URL for your app's database projectId - The Project ID for your app storageBucket - The Storage Bucket for your app messagingSenderId - The ID of the messaging sender for your app appId - The ID of the app your app is running on measurementId - If provided, the code uses this as the name of a Google Analytics measurement.

    Shortcut: firebase.web.db.init

    import { initializeApp } from 'firebase/app';
    import { getDatabase } from "firebase/database";
    
    // TODO: Replace with your app's Firebase project configuration
    const firebaseConfig = {
      apiKey: "API_KEY",
      authDomain: "PROJECT_ID",
      // The value of `databaseURL` depends on the location of the database
      databaseURL: "Database URL",
      projectId: "PROJECT_ID",
      storageBucket: "PROJECT_ID.appspot.com",
      messagingSenderId: "SENDER_ID",
      appId: "APP_ID",
      // For Firebase JavaScript SDK v7.20.0 and later, `measurementId` is an optional field
      measurementId: "G-MEASUREMENT_ID",
    };
    
    const app = initializeApp(firebaseConfig);
    
    // Get a reference to the database service
    const database = getDatabase(app);
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.