Reputation: 453
Should i initialize my const firebaseConfig = {};
for every js file? on html
Upvotes: 0
Views: 618
Reputation: 364
You haven't mentioned the type of project you are working on.
Here is how it is done in React project
Firebase
folder under src
in React projectconfig.js
in Firebase
folderInitialize the app in config.js
and export it
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
// Replace the following with your app's Firebase project configuration
const firebaseConfig = {
apiKey: //your API key,
authDomain: "random-project.com"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
export {app, db}
// some other file
import { db } from '../Firebase/config';
const citiesCol = collection(db, 'cities');
const citySnapshot = await getDocs(citiesCol);
You can read in more depth in official docs here:https://firebase.google.com/docs/web/setup
Upvotes: 1