Skip to content

Instantly share code, notes, and snippets.

@dmitriyzyuzin
Created August 4, 2021 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriyzyuzin/d7f690470c762b96a20af3fdb386e0da to your computer and use it in GitHub Desktop.
Save dmitriyzyuzin/d7f690470c762b96a20af3fdb386e0da to your computer and use it in GitHub Desktop.
Save data to firebase (firestore)
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