Coding Notes

Firebase

By Rae

Firebase

Cloud-based platform

For mobile apps

Notes

  • Script tags in HTML are where you can write JS. add src="filename" to link js file to HTML file.
  • const: appSettings = {databaseURL: "referenceURL"}
  • import { initializeApp } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js"
  • const app = initializeApp(appSettings)
  • import { getDatabase, ref, push } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"
  • const database = getDatabase(app)
  • const name = ref(database, "what the reference should be called")
  • push(where you want to push it (name), what you want to push)
  • Security Rules
    • using test mode allows anyone with the database reference to view edit and delete the data in your database.
    • the default for testmode is set to a max of 30 days. (how long test mode lasts)
    • to change the max testmode write and read time go to Realtime Database then Rules. If you change them both to true anyone will always be able to read or write in the database.
  • To create a section press the plus next to the url and add a key, then press the plus next to your section name.
  • import { onValue } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"
  • onValue(where you want to fetch the data from (name), function(snapshot){})
  • onValue runs every time there's a change to the database.
  • to change a key or value in the database just click it and edit it.
  • inmport { remove } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"