Skip to content

Cubicl3s/Personal-Blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Firebase Firestore Demo: A Simple Blog Post App

This demo project demonstrates how to integrate Firebase Firestore into a simple web application for storing and displaying blog posts. You will learn how to use Firestore to store, retrieve, and display data on a webpage using HTML, CSS, and JavaScript.

Overview of Firebase Firestore

Firebase Firestore is a scalable and flexible NoSQL cloud database that helps store and sync data in real-time for web and mobile applications. You can think of Firestore as a cloud version of a JSON database where data is organized into collections and documents.

  • Collection: A collection is a group of documents.
  • Document: A document is a set of key-value pairs (like a JSON object).
  • Field: A field is a key-value pair inside a document.

This demo will focus on using Firestore to store blog posts, which consist of a title and body.

Features

  • Store Blog Posts: Allow users to enter a title and body for a blog post, which is then saved to Firestore.
  • Retrieve Blog Posts: Display the stored blog posts dynamically on the page.
  • Real-time Updates: Firestore can automatically update the UI when new posts are added or existing ones are modified.

How Firebase Firestore Works

  • Firestore Database: Firestore stores data in collections, and each collection contains documents. Each document contains fields with data (similar to a key-value pair).

    Example:

    • Collection: posts
      • Document: post1
        • Fields: title: "My First Post", body: "This is the body of the post"
  • Real-Time Data: Firebase Firestore allows you to read and write data in real-time. When the data changes in the database, the changes are automatically reflected on any connected client.


Step-by-Step Guide

Step 1: Set Up Firebase Project

  1. Go to Firebase Console: Navigate to Firebase Console, and create a new project.

  2. Enable Firestore:

    • In the Firebase Console, go to Firestore Database in the left sidebar.
    • Click on Create database and choose Start in test mode (or choose production mode if you want to add security rules).
  3. Get Firebase Config:

    • In the Firebase Console, go to Project Settings > General > Your Apps > Firebase SDK snippet.
    • Copy the Firebase config object. This will contain your apiKey, authDomain, projectId, and other details.

Step 2: Set Up the Project

  1. Create a folder for your project and inside it create the following files:

    • index.html – The structure of the web page.
    • app.js – JavaScript for interacting with Firestore.
    • README.md – Documentation on how to set up and use the app.
  2. Copy and paste the provided code snippets into their respective files.

Step 3: Test the Application

  1. Open the index.html file in your browser.
  2. Enter a blog post title and body, and click the "Save Post" button.
  3. The post will be saved to Firestore and displayed on the page.

Conclusion

This demo shows how to:

  1. Integrate Firebase into a webpage using HTML, CSS, and JavaScript.
  2. Store and Retrieve Data in Firestore.
  3. Display Data dynamically on the webpage.

By following this approach, you can build more complex apps like a full-fledged blog system, a task manager, or a chat application.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published