0
0
Firebasecloud~5 mins

First Firebase integration - Commands & Configuration

Choose your learning style9 modes available
Introduction
Firebase helps you add backend features like databases and user login to your app without managing servers. This guide shows how to start using Firebase in a simple app.
When you want to add user login to your mobile or web app quickly.
When you need a real-time database that updates instantly for all users.
When you want to store files like images or videos in the cloud easily.
When you want to track app usage and errors without setting up your own tools.
When you want to host a simple website with backend features included.
Config File - firebase.json
firebase.json
{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

This file configures Firebase Hosting for your app.

  • public: folder with your website files.
  • ignore: files Firebase should skip when deploying.
  • rewrites: sends all requests to index.html for single-page apps.
Commands
Installs the Firebase command line tool globally so you can use Firebase commands anywhere.
Terminal
npm install -g firebase-tools
Expected OutputExpected
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/bin/firebase + firebase-tools@latest added 123 packages from 45 contributors in 12.3s
Logs you into your Google account to allow Firebase commands to access your projects.
Terminal
firebase login
Expected OutputExpected
✔ Success! Logged in as your-email@example.com
Starts setup for your Firebase project. You choose features like Hosting or Firestore and link your project.
Terminal
firebase init
Expected OutputExpected
You're about to initialize a Firebase project in this directory. ? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm. ◯ Firestore: Configure security rules and indexes files for Firestore ◯ Functions: Configure and deploy Cloud Functions ◯ Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys ◯ Storage: Configure a security rules file for Cloud Storage ◯ Emulators: Set up local emulators for Firebase features ? Please select an option: Hosting ? Select a default Firebase project for this directory: example-project ? What do you want to use as your public directory? public ? Configure as a single-page app (rewrite all urls to /index.html)? Yes ? Set up automatic builds and deploys with GitHub? No Firebase initialization complete!
Uploads your app files and configuration to Firebase so your app is live on the internet.
Terminal
firebase deploy
Expected OutputExpected
=== Deploying to 'example-project'... i deploying hosting i hosting: preparing public directory for upload... ✔ hosting: public directory prepared. ✔ hosting: 3 files uploaded successfully ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/example-project/overview
Opens your deployed website in the default web browser so you can see your live app.
Terminal
firebase open hosting:site
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: Firebase CLI lets you set up and deploy backend features quickly without managing servers.

Common Mistakes
Not running 'firebase login' before 'firebase init' or 'firebase deploy'
Firebase commands need your Google account access to link and deploy projects; without login, commands fail.
Always run 'firebase login' first to authenticate your account.
Choosing the wrong public directory during 'firebase init'
If the public directory does not contain your app files, deployment will upload empty or wrong files.
Set the public directory to the folder where your website files (like index.html) are located, usually 'public'.
Skipping the single-page app rewrite option when using frameworks like React or Angular
Without rewrite, routing inside your app breaks because Firebase tries to find files for each URL.
Choose 'Yes' to rewrite all URLs to index.html during 'firebase init' for single-page apps.
Summary
Install Firebase CLI to run Firebase commands from your terminal.
Log in to your Google account with 'firebase login' to access your projects.
Initialize your project with 'firebase init' to set up hosting and link your Firebase project.
Deploy your app to Firebase Hosting using 'firebase deploy' to make it live.
Open your live app in a browser with 'firebase open hosting:site'.