0

I have the following configuration file in my nodejs project

const firebase = require('firebase/app');

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "AIzaSyBNMB7IdCKV7iObJDSSFTRVHp9M8ZndpZh2c",
  authDomain: "ivrs-d422d.firebaseapp.com",
  databaseURL: "https://ivrs-d422d.firebaseio.com",
  projectId: "ivrs-d422d",
  storageBucket: "ivrs-d422d.appspot.com",
  messagingSenderId: "10387822329211",
  appId: "1:1038786929211:web:6ed1a58fewqa9855105ef21e",
  measurementId: "G-ZTY9VS9EK9"
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

const db = firebase.database();

and i get the following error:

/Users/Documents/Market/config/firebaseConfiguration.js:26
  const db = firebase.database();
                      ^

TypeError: firebase.database is not a function
    at Object.<anonymous> 
(/Users/Documents/Market/config/firebaseConfiguration.js:26:23)

Can someone explain why that is happening?

Learn2Code
  • 1,974
  • 5
  • 24
  • 46
  • Please refer to the documentation on Firebase v9's breaking changes: [Modular Web SDK Upgrade Guide](https://firebase.google.com/docs/web/modular-upgrade) – samthecodingman Dec 21 '21 at 04:07
  • Does this answer your question? [Firebase RTDB for Firebase v9](https://stackoverflow.com/q/69594428/3068190) – samthecodingman Dec 21 '21 at 04:13

1 Answers1

0

Seems like you need to use:

import { getFirestore } from "firebase/firestore"

const db = getFirestore()

for Realtime database.

import { getDatabase } from "firebase/database";
const database = getDatabase(app);

Docs for Realtime database setup https://firebase.google.com/docs/database/web/start#initialize_the_javascript_sdk

Docs for Firestore setup https://firebase.google.com/docs/firestore/quickstart#initialize

aj griffin
  • 93
  • 6
  • I am wanting to connect to the firebase realtime database and not firestore. – Learn2Code Dec 21 '21 at 03:36
  • my bad. seems like you're using Firebase 9, and setting up the old way. firebase 9 broke things up so you wouldn't need to import the entire Firebase as far as I understand. https://firebase.google.com/docs/database/web/start#initialize_the_javascript_sdk lmk if this work – aj griffin Dec 21 '21 at 03:50