firebase use --add code example
Example 1: firebase cli windows
npm install -g firebase-tools
Example 2: add firebase in react
import * as firebase from 'firebase'
const firebaseConfig = {
apiKey: "AIzaSyC6EDL8gMkZc3GGzGveMqWe5zvAr5DNiL4",
authDomain: "blood-components.firebaseapp.com",
databaseURL: "https://blood-components.firebaseio.com",
projectId: "blood-components",
storageBucket: "blood-components.appspot.com",
messagingSenderId: "388223113819",
appId: "1:388223113819:web:1273570a12add0fedafd7e",
measurementId: "G-K6NM078FWD"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
const db = firebase.firestore();
//initiating references to the databases
const usersRef = db.collection('users')
// for privileges purposes
const functions = firebase.functions();
//google provider sign-in
const googleProvider = new firebase.auth.GoogleAuthProvider();
export { firebase, db, auth, functions, googleProvider }
Example 3: add to firebase database
db.collection("cities").add({
name: "Tokyo",
country: "Japan"
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
Example 4: firebase tools install
installing firebase tools