📖 Scenario: You are creating a simple website and want to host it using Firebase Hosting. This project will guide you through setting up Firebase Hosting step-by-step, so your website can be live on the internet.
🎯 Goal: Set up Firebase Hosting for a website by initializing Firebase in your project, configuring the hosting settings, deploying the site, and confirming the deployment.
📋 What You'll Learn
Create a Firebase project configuration file
Add a hosting configuration to the Firebase config
Write the deployment command in the configuration
Complete the Firebase hosting setup for deployment
💡 Why This Matters
🌍 Real World
Hosting websites on Firebase is common for developers who want fast, secure, and scalable hosting without managing servers.
💼 Career
Understanding Firebase Hosting setup is useful for roles in web development, DevOps, and cloud infrastructure management.
Progress0 / 4 steps
1
Create Firebase project configuration file
Create a file named firebase.json with the exact content: {"hosting": {"public": "public"}} to specify the hosting public directory.
Firebase
Hint
This file tells Firebase where your website files are located.
2
Add hosting configuration to Firebase config
Add a firebaseConfig object in a file named firebaseConfig.js with these exact keys and values: apiKey: "AIza...", authDomain: "your-project.firebaseapp.com", projectId: "your-project", storageBucket: "your-project.appspot.com", messagingSenderId: "1234567890", appId: "1:1234567890:web:abcdef".
Firebase
Hint
This config connects your app to your Firebase project.
3
Write deployment command in package.json scripts
In package.json, add a scripts section with a deploy command that runs firebase deploy --only hosting exactly.
Firebase
Hint
This script lets you deploy your site with one command.
4
Complete Firebase hosting setup for deployment
Add the firebase init hosting command in your terminal to initialize hosting, then confirm the public directory is set to public and choose to configure as a single-page app by typing y.
Firebase
Hint
This command sets up Firebase Hosting interactively.
Practice
(1/5)
1. What is the main purpose of Firebase Hosting?
easy
A. To create databases for mobile apps
B. To write backend server code
C. To publish websites online without managing servers
D. To monitor app performance
Solution
Step 1: Understand Firebase Hosting's role
Firebase Hosting is designed to host and serve web content easily without needing to manage servers.
Step 2: Differentiate from other Firebase services
Other services like databases or backend code are separate from Hosting's purpose.
Final Answer:
To publish websites online without managing servers -> Option C
Quick Check:
Firebase Hosting = publish websites without servers [OK]
Hint: Remember Hosting is for websites, not databases or code [OK]
Common Mistakes:
Confusing Hosting with Firebase database services
Thinking Hosting manages backend code
Assuming Hosting monitors app performance
2. Which command initializes Firebase Hosting in your project?
easy
A. firebase init hosting
B. firebase deploy --only hosting
C. firebase start hosting
D. firebase create hosting
Solution
Step 1: Identify the initialization command
The command to set up Firebase Hosting configuration is firebase init hosting.
Step 2: Differentiate from deployment commands
firebase deploy --only hosting publishes the site but does not initialize it.
Final Answer:
firebase init hosting -> Option A
Quick Check:
Initialize Hosting = firebase init hosting [OK]
Hint: Init sets up Hosting; deploy publishes it [OK]
Common Mistakes:
Using deploy command to initialize
Assuming 'firebase start hosting' exists
Confusing create with init
3. After running firebase deploy --only hosting, what happens?
medium
A. Firebase deletes your local project files
B. Your website files are uploaded and become live at a Firebase URL
C. Your database is reset to default
D. Firebase Hosting configuration is removed
Solution
Step 1: Understand the deploy command effect
The deploy command uploads your site files to Firebase Hosting and makes the site live.
Step 2: Eliminate incorrect options
Deploy does not delete local files, reset databases, or remove configuration.
Final Answer:
Your website files are uploaded and become live at a Firebase URL -> Option B
Quick Check:
Deploy Hosting = upload and go live [OK]
Hint: Deploy publishes your site live on Firebase URL [OK]
Common Mistakes:
Thinking deploy deletes local files
Confusing deploy with database reset
Assuming deploy removes Hosting setup
4. You ran firebase deploy --only hosting but your site did not update. What is a likely cause?
medium
A. You deployed to the wrong Firebase project
B. Your internet connection was too fast
C. You forgot to run firebase init hosting first
D. Firebase Hosting does not support updates
Solution
Step 1: Check project targeting
If you deploy to the wrong Firebase project, your site won't update as expected.
Step 2: Rule out other options
Init is needed only once; internet speed does not block updates; Hosting supports updates.
Final Answer:
You deployed to the wrong Firebase project -> Option A
Quick Check:
Wrong project deploy = no site update [OK]
Hint: Verify project ID before deploying [OK]
Common Mistakes:
Assuming init must run every deploy
Blaming internet speed for deployment failure
Thinking Hosting can't update sites
5. You want to deploy only your website without affecting other Firebase services. Which command should you use?
hard
A. firebase deploy
B. firebase deploy --only database
C. firebase deploy --except hosting
D. firebase deploy --only hosting
Solution
Step 1: Understand deployment scope flags
The --only hosting flag deploys just the Hosting service, leaving others untouched.
Step 2: Compare other options
firebase deploy deploys all configured services; --only database deploys only database; --except hosting deploys all except Hosting.
Final Answer:
firebase deploy --only hosting -> Option D
Quick Check:
Deploy only Hosting = firebase deploy --only hosting [OK]
Hint: Use --only hosting to deploy just the website [OK]
Common Mistakes:
Running deploy without --only and affecting all services
Using --only database instead of hosting
Using --except hosting to deploy Hosting
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.