firebase_cli

Master the Firebase CLI for efficient project management. Learn installation, usage, and essential commands to deploy, configure, and interact with Firebase services like Hosting, Functions, Firestore, and more.

Firebase CLI

Firebase CLI Guide

The Firebase CLI (Command Line Interface) is an indispensable tool for developers looking to streamline their workflow with Firebase services. It empowers you to manage your Firebase projects directly from your terminal, offering efficient ways to deploy applications, configure databases, set up authentication, and much more. This guide will walk you through the installation, basic usage, and essential commands of the Firebase CLI, helping you leverage its full potential.

Firebase CLI Installation

Before you can start using the Firebase CLI, ensure you have Node.js and npm (Node Package Manager) installed on your system. If not, download and install them from the official Node.js website.

Once Node.js and npm are set up, open your terminal or command prompt and execute the following command to install the Firebase CLI globally:

npm install -g firebase-tools

After the installation completes, verify it by running:

firebase --version

This command should display the installed version of the Firebase CLI, confirming a successful installation.

Firebase CLI Usage Overview

The Firebase CLI provides a robust set of commands to interact with various Firebase services. Key functionalities include initializing new Firebase projects, deploying web applications to Firebase Hosting, managing Realtime Database and Cloud Firestore, configuring Cloud Functions, and utilizing local emulators for development and testing.

The general syntax for using the CLI is:

firebase <command> [options]

For comprehensive details on all available commands and their parameters, you can use the help command:

firebase help

Essential Firebase CLI Commands

Here are some of the most frequently used Firebase CLI commands:

Project Initialization and Management

  • firebase init: Initializes a new Firebase project in your current directory. You can specify which services to set up, such as Hosting, Functions, or Firestore.
    Example: firebase init hosting
  • firebase use: Sets the active Firebase project for your local environment.
    Example: firebase use my-firebase-project-id
  • firebase use --add: Adds an existing Firebase project to your local configuration.
    Example: firebase use --add
  • firebase projects:create: Creates a new Firebase project.
    Example: firebase projects:create --display-name "My New App"

Deployment and Serving

  • firebase deploy: Deploys your project's resources to Firebase. You can deploy specific services using flags.
    Example: firebase deploy --only hosting
  • firebase serve: Starts local development servers and emulators for services like Hosting and Functions, allowing for local testing.
    Example: firebase serve --only functions,firestore

Authentication and User Management

  • firebase auth: Provides commands to manage Firebase Authentication, including exporting user data.
    Example: firebase auth:export users.json

Database Management

  • firebase database: Commands for interacting with Firebase Realtime Database.
    Example: firebase database:get /data
  • firebase firestore: Commands for interacting with Firebase Cloud Firestore.
    Example: firebase firestore:delete collection/document

Cloud Functions

  • firebase functions: Commands for deploying, managing, and interacting with Firebase Cloud Functions.
    Example: firebase functions:config:set api_key=12345

Other Services

  • firebase hosting: Commands specifically for managing Firebase Hosting configurations and deployments.
    Example: firebase hosting:disable
  • firebase remoteconfig: Commands to manage Firebase Remote Config templates.
    Example: firebase remoteconfig:get template
  • firebase ext: Commands for installing and managing Firebase Extensions.
    Example: firebase ext:install firebasestorage/firestore-permissions
  • firebase appdistribution: Commands for interacting with Firebase App Distribution to manage test builds.
    Example: firebase appdistribution:testers:list

Authentication and Logout

  • firebase login: Authenticates the Firebase CLI with your Google account.
    Example: firebase login --no-localhost
  • firebase logout: Logs out the currently authenticated user from the Firebase CLI.
    Example: firebase logout

For more in-depth information and advanced usage, refer to the official Firebase CLI documentation.