Create and Deploy a Website to Firebase

Overview

Scenario

In this scenario, you are preparing for an upcoming interview with a company that uses Firebase Hosting. You need to create a personal portfolio web page on the internet that you can share with the employer. The job description states that a minimum requirement is experience with Google Firebase Hosting, and the preferred candidates will have used Node.js. In this assignment, you will use both.

Business Requirements

Project Requirements

Table of Contents

Instructions

Watch the video instead: Firebase Hosting Setup Video

Step 1: Install Visual Studio Code and Node.js

Hopefully, you already have Visual Studio Code and Node.js installed on your computer. If not, ask ChatGPT how to install them and follow the instructions from ChatGPT.

Step 2: Create a New Project in Firebase?

  1. Sign into the Google Firebase console using your BYU-Idaho email address (the email address with numbers, for example: bos24011@byui.edu).
    • Trouble signing in? Open my.byui.edu, click “Profile”, scroll down to “Campus Email”, and use that email for the Google Firebase sign in

      my.byui.edu View Profile option my.byui.edu Profile Email
    • If that doesn’t work, use a personal Gmail account.
  2. Click Add Project.

    Firebase Add Project
  3. Name your Project with your name and accept the terms

    Firebase Name Project
  4. Enable Google Analytics

    Firebase Enable Google Analytics
  5. Use default settings and accept terms

    Firebase Enable Google Analytics 2
  6. Wait for creation to complete

    Firebase Wait for Creation
    Firebase Creation Complete

Step 3: Create Necessary Files in VS Code

  1. Open Visual Studio Code (VS Code) and click File > New Window

    VS Code New Window
  2. Click Open Folder or on Mac Open (not open folder) to open a new folder

    VS Code Open Folder

    Click New Folder (on Mac) or right-click and choose New > Folder (on Windows) and make a new project folder called firebaseproject or a name of your choice and open it.

  3. Click Yes, I trust the authors

    VS Code Trust Authors
  4. In VS Code, create a new folder called public inside the project (it must be called public) by clicking on the + folder icon.

    VS Code New Folder
  5. Type public for the new folder name

    VS Code Public Folder
  6. Click on the public folder to select it

    VS Code Select Public
  7. Make a new file by clicking on the + file icon (make sure the public folder is still selected)

    VS Code New File
  8. Make the index.html file inside the public folder (notice that it is indented a little). Make sure it is indented so that it is inside the public folder.

    VS Code Index.html
  9. Create another new file by clicking on the + file icon.

    VS Code New File
  10. Type the filename styles.css to create the styling file for your web pages. (If your CSS file is not indented under the public folder, drag it into there).

    VS Code Styles.css
  11. Make sure the styles.css and the index.html files are indented with a line like this image below so that you know it is in the public folder

    VS Code Public Folder Files
  12. Open the terminal in VS Code by clicking on the Terminal menu > New Terminal

    VS Code Terminal New

    In that new terminal window, run the commands given below

Step 4: Install Google Firebase by asking ChatGPT

  1. Sign into ChatGPT

    • Start a new chat

      ChatGPT Start Chat
  2. In the new chat prompt at the bottom, type How can I make a simple Firebase web page that uses node.js?

    • NOTE: If ChatGPT asks you to install express or admin tools, you don’t need to do that. Sometimes, ask ChatGPT the same thing a few times. You will get better results as you analyze them.

    ChatGPT Prompt 1
  3. For Windows machines: Change the execution policy

    • Search for PowerShell and run it as administrator.

    • Run the following command: Set-ExecutionPolicy RemoteSigned

    • Type A and press enter

  4. The prompts/commands ChatGPT provides should be run in the terminal in VS Code. For MAC Users, you may have to put sudo in front of the commands.

    For example, ChatGPT should prompt you to install Firebase using npm (node package manager). (-g means to install it globally)

    Firebase Install Tools
  5. Click Copy Code from ChatGPT then paste it in the terminal in VS Code. Hit Return/Enter to run it

    Terminal Run Install
    • It should install a few things and it might look like this:

      Terminal Install Progress
    • When firebase is installed, it should look something like this:

      Terminal Install Complete

Step 5: Login to Firebase with your account

  1. Login to firebase in your VS Code terminal with the command firebase login

    Firebase Login
  2. Type n and press Return/Enter to not submit usage and error information

    Firebase Login No Usage
  3. Login as needed and you may see this page in your terminal window

    Firebase Login Notice
  4. Login with your byui.edu email address, accept the terms and click continue

    Firebase Login BYU-I
  5. Allow the firebase CLI (command line interface) to access Google

    Firebase Login BYU-I 2
  6. You should see a success prompt in the browser and in the terminal

    Firebase Login Success Terminal Firebase Login Success

Step 6: Initialize Firebase in your project

  1. Initialize the firebase project by typing in firebase init in the terminal in VS code

    Firebase Init

    Take note of the directory it gives. When configuring multiple firebase projects, you need to be in a different directory for each.

    Type y to proceed and type Return/Enter

  2. Use the arrows on your keyboard to select Hosting: Configure files for Firebase hosting and (optionally) set up GitHub action deploys. Press the space bar on your keyboard followed by Return/Enter.

    Firebase Init Select
  3. Use the arrows on your keyboard to select Use and existing Project and press Return/Enter. This will allow us to choose a project we previously in Google Firebase

    Firebase Init Select 2
  4. Pick the name of the project you made previously by using the arrow keys on your keyboard and then press Return/Enter.

    Firebase Init Select 3
  5. Choose the public folder (provided by default) by pressing Return/Enter on your keyboard.

    Firebase Init Select 4
  6. Do not configure it as a single-page app by typing n and press Return/Enter

    Firebase Init Select 5
  7. We won’t set it up with GitHub for automatic builds and deploys, so type n and press Return/Enter.

    Firebase Init Select 6
  8. We want to overwrite the index.html file. Type y then press Return/Enter.

    Firebase Init Select 7

Step 7: Deploy your project to Firebase

  1. Type firebase deploy in the terminal. This will deploy your code to a website URL that you can share with others (You must run this each time you modify your code to push the changes to the cloud).

    Firebase Deploy
  2. Copy the Hosting URL and paste it in a new tab in your browser

  3. The URL should be something like https://yourproject.web.app and will look something like this:

    Firebase Deploy Success

Step 8: Create a Profile web page using AI and deploy to Firebase Hosting

  1. In VS Code, double-click the index.html file we created in the public folder and delete all of the code. You can also press (CMD/CTRL + A to select all and then Delete/Backspace).

  2. Ask ChatGPT the following Please give me code for my index.html file and a styles.css file that would be a nice portfolio page and link them

  3. Click Copy Code for the index.html file and paste it into that file in VS Code

  4. Paste the HTML code from ChatGPT into the file, or click Edit > Paste from the menu, or press CMD/CTRL + V

  5. Save the file with File > Save from the menu or press CMD/CTRL + V.

    • This HTML code is to provide the text and structure for the web page.

  6. Now do the same thing with the CSS code provided by ChatGPT. If you don’t have CSS code, ask ChatGPT for it.

  7. In VS Code, delete all the content from the styles.css file and paste in the provided code.

  8. Save the file.

    • The WDD 130 Course teaches more about HTML and CSS

  9. Run firebase deploy again in the terminal to push your changes to Firebase

  10. Refresh the URL in your browser by clicking the refresh button while holding shift on your keyboard. This will refresh the cache of the page.

Step 9: Ask ChatGPT questions

  1. Ask ChatGPT about any concepts that you don’t understand or you are unsure of

    • What is Node.js?
    • What is the purpose of Node.js within a web application?
    • What is hosting?
    • Can you make a website without hosting?

Troubleshooting & Common Problems

Permission Errors or firebase installation not working

If firebase doesn’t deploy

Error: No firebase projects associated with this account

The website doesn’t load the styles, but only the words appear

Firebase Hosting page is a default page

Node.js is not able to run

Cannot get Firebase to finish setting up and installing

Learning More

Classes to take

Build Your Resume

Improve Your Site

Adding SCSS (WDD331R teaches SCSS and preprocessors)