scrimba
Code with AI
Build with Firebase
Get set up with Firebase
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Get set up with Firebase
AboutCommentsNotes
Get set up with Firebase
Expand for more info
index.js
run
preview
console
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.20.0/firebase-app.js"
import { getDatabase, ref, push, onValue } from "https://www.gstatic.com/firebasejs/9.20.0/firebase-database.js"

// Your web app's Firebase configuration. You will get this when you create a new Firebase project.
const firebaseConfig = {
databaseURL: "https://sample-project-2c26b-default-rtdb.europe-west1.firebasedatabase.app",
}

// Your web app's Firebase configuration
const app = initializeApp(firebaseConfig)
const database = getDatabase(app)
const thingsRef = ref(database, "things")

// Page elements
const inputFieldEl = document.getElementById("input-field")
const pushButtonEl = document.getElementById("push-button")
const thingsEl = document.getElementById("things")

// Firebase functions
pushButtonEl.addEventListener("click", function() {
let inputValue = inputFieldEl.value
push(thingsRef, inputValue)
})

onValue(thingsRef, function(snapshot) {
if (snapshot.exists()) {
let things = Object.values(snapshot.val())
thingsEl.innerHTML = ""

for (let i = 0; i < things.length; i++) {
thingsEl.innerHTML += `<li>${things[i]}</li>`
}
} else {
thingsEl.innerHTML = "No things yet"
}
})
Console
"[2023-12-07T14:06:30.061Z] @firebase/database:"
,
"FIREBASE WARNING: Firebase error. Please ensure that you have the URL of your Firebase Realtime Database instance configured correctly. (https://sample-project-2c26b-default-rtdb.europe-west1.firebasedatabase.app/) "
,
/index.html
-3:35