Firebase
Firebase is an app development platform that helps you build and grow apps and games users love.
- JavaScript
- Python
Comming soon
We are releasing new Python features every week
Credential configuration
The form fields are the fields of an object provided by Firebase, to connect by your app. So, first of all, you need to create a project in Firebase, and then you need to create an app in this project. If you want to find more information about creating a project and an app, you may find more information here.
Once you have the app, you will see it on the project settings section, in the General tab.
Click on the app you want to use, and you'll be able to see a section called SDK setup and configuration,
where you can find firebaseConfig
object. Fill the form fields with this object values.
In the extra options field, you can provide most of the parameters found here.
Here is an example of a filled credential configuration form in YepCode:
Firebase Snippets available in YepCode editor
The title is the triggering text for YepCode to autocomplete the script.
- JavaScript
- Python
Integration
const firebase = yepcode.integration.firebase("credential-slug");
const { initializeApp } = require("firebase/app");
const firebaseConfig = {
apiKey: "firebase-app-apiKey",
authDomain: "firebase-app-authDomain",
projectId: "firebase-app-projectId",
storageBucket: "firebase-app-storageBucket",
messagingSenderId: "firebase-app-messagingSenderId",
appId: "firebase-app-appId"
};
const firebase = initializeApp(firebaseConfig);
When you init the credential, it creates some background resources. So you should free it at the end of your processes. Otherwise, they will not end until you kill it! Adding this code will free the resources and make the process end in a normal way:
const { deleteApp } = require("firebase/app");
deleteApp(firebase);
Insert Item into Realtime Database
const { getDatabase, ref, set } = require("firebase/database");
const db = getDatabase(firebase);
await set(ref(db, `path-to-the-object`), {
// Object content
});
Get Item from Realtime Database
const { getDatabase, ref, get, child } = require("firebase/database");
const db = getDatabase(firebase);
const dbRef = ref(db);
get(child(dbRef, `path-to-the-object`)).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
Insert Item into Firestore
const { getFirestore, collection, addDoc } = require("firebase/firestore");
const db = getFirestore(firebase);
await addDoc(collection(db, "collection-name"), {
// The object data
}).then(console.log).catch(console.error);
List Items from Firestore
const { getFirestore, collection, getDocs } = require("firebase/firestore");
const db = getFirestore(firebase);
const querySnapshot = await getDocs(collection(db, "collection-name"));
querySnapshot.forEach((doc) => {
console.log(doc.id);
console.log(doc.data());
});
Delete Item from Firestore
const { getFirestore, deleteDoc, doc } = require("firebase/firestore");
const db = getFirestore(firebase);
await deleteDoc(doc(db, "collection-name", "document-id"));
Comming soon
We are releasing new Python features every week