Created
August 4, 2021 20:22
-
-
Save dmitriyzyuzin/d7f690470c762b96a20af3fdb386e0da to your computer and use it in GitHub Desktop.
Save data to firebase (firestore)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const firebase = require('firebase'); | |
require('firebase/firestore'); | |
// firebase DB | |
const firebaseConfig = { | |
apiKey: '', | |
authDomain: '', | |
projectId: "", | |
storageBucket: "", | |
messagingSenderId: "", | |
appId: "", | |
measurementId: "" | |
}; | |
firebase.initializeApp(firebaseConfig); | |
const db = firebase.firestore(); | |
const COLLECTION_NAME = 'collection-name'; | |
const saveDataToFirestore = (data) => { | |
db.collection(COLLECTION_NAME) | |
.doc('doc-name') | |
.set({ | |
data, | |
}) | |
.then((docRef) => { | |
console.log(`Saved data: ${data}`); | |
}) | |
.catch((error) => { | |
console.error("Error adding document: ", error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment