Convert Figma logo to code with AI

firebase logofirebase-tools

The Firebase Command Line Tools

4,016
933
4,016
623

Top Related Projects

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.

Firebase Javascript SDK

Firebase Admin Python SDK

Firebase SDK for Apple App Development

Firebase Android SDK

Quick Overview

Firebase Tools is the official command-line interface (CLI) for Firebase, providing a set of tools for managing and deploying Firebase projects. It allows developers to interact with various Firebase services, configure project settings, and automate deployment processes directly from the command line.

Pros

  • Seamless integration with Firebase services and Google Cloud Platform
  • Powerful CLI commands for managing Firebase projects, including deployment, database management, and hosting configuration
  • Supports local emulation of Firebase services for testing and development
  • Enables easy implementation of continuous integration and deployment (CI/CD) workflows

Cons

  • Learning curve for developers new to Firebase or command-line tools
  • Some advanced features may require additional configuration or setup
  • Occasional versioning issues when working with multiple Firebase projects
  • Limited GUI options for users who prefer graphical interfaces

Code Examples

  1. Initializing a Firebase project:
firebase init

This command initializes a new Firebase project in the current directory, prompting the user to select desired Firebase features and configure project settings.

  1. Deploying a Firebase project:
firebase deploy

This command deploys the current project to Firebase, including hosting files, Cloud Functions, and other configured services.

  1. Running Firebase emulators:
firebase emulators:start

This command starts local emulators for Firebase services, allowing developers to test their applications without connecting to production Firebase services.

Getting Started

To get started with Firebase Tools:

  1. Install Node.js and npm (Node Package Manager)
  2. Install Firebase Tools globally:
    npm install -g firebase-tools
    
  3. Log in to your Firebase account:
    firebase login
    
  4. Navigate to your project directory and initialize Firebase:
    cd your-project-directory
    firebase init
    
  5. Follow the prompts to set up your project
  6. Deploy your project:
    firebase deploy
    

For more detailed instructions and advanced usage, refer to the official Firebase documentation.

Competitor Comparisons

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.

Pros of react-native-firebase

  • Specifically designed for React Native, offering better integration and performance
  • Provides a more comprehensive set of Firebase features tailored for mobile development
  • Offers TypeScript support out of the box

Cons of react-native-firebase

  • Limited to React Native projects, not suitable for web or other platforms
  • May have a steeper learning curve for developers new to React Native
  • Potentially slower updates compared to the official Firebase SDK

Code Comparison

firebase-tools (JavaScript):

const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();

react-native-firebase (JavaScript):

import firebase from '@react-native-firebase/app';
import '@react-native-firebase/firestore';
const db = firebase.firestore();

Summary

firebase-tools is the official Firebase CLI and admin SDK, suitable for various platforms and server-side operations. react-native-firebase is a community-driven project specifically designed for React Native mobile development. While react-native-firebase offers better integration with React Native and mobile-specific features, it's limited to that ecosystem. firebase-tools provides broader platform support but may require additional setup for optimal mobile performance. The choice between the two depends on the project's requirements and target platform.

Firebase Javascript SDK

Pros of firebase-js-sdk

  • Provides direct client-side access to Firebase services
  • Offers real-time data synchronization capabilities
  • Supports offline persistence and automatic reconnection

Cons of firebase-js-sdk

  • Larger bundle size, potentially impacting application performance
  • Limited to client-side usage, not suitable for server-side operations
  • Requires careful security rules implementation to prevent unauthorized access

Code Comparison

firebase-js-sdk:

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, addDoc } from 'firebase/firestore';

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
await addDoc(collection(db, 'users'), { name: 'John Doe' });

firebase-tools:

firebase init firestore
firebase deploy --only firestore
firebase emulators:start --only firestore

The firebase-js-sdk is primarily used for client-side integration with Firebase services, allowing direct interaction with Firestore, Authentication, and other Firebase features. It's ideal for building real-time web and mobile applications.

On the other hand, firebase-tools is a command-line interface for Firebase, used for project initialization, deployment, and local development. It's essential for setting up Firebase projects, managing deployments, and running local emulators for testing.

While firebase-js-sdk focuses on runtime functionality, firebase-tools is crucial for development workflow and project management. Both tools complement each other in the Firebase ecosystem, catering to different aspects of application development and deployment.

Firebase Admin Python SDK

Pros of firebase-admin-python

  • Specifically designed for Python developers, offering a more native and Pythonic experience
  • Provides direct access to Firebase services from server-side Python applications
  • Supports asynchronous operations, which can be beneficial for certain use cases

Cons of firebase-admin-python

  • Limited to server-side operations, lacking client-side functionality
  • Narrower scope compared to firebase-tools, focusing primarily on admin SDK features
  • May require additional setup for local development and testing environments

Code Comparison

firebase-admin-python:

import firebase_admin
from firebase_admin import credentials, firestore

cred = credentials.Certificate("path/to/serviceAccount.json")
firebase_admin.initialize_app(cred)
db = firestore.client()

firebase-tools (using Firebase CLI):

firebase init
firebase deploy

Summary

firebase-admin-python is tailored for Python developers working on server-side applications, offering a more focused and language-specific approach. It excels in providing direct access to Firebase services but is limited to admin SDK features. firebase-tools, on the other hand, offers a broader range of functionalities, including deployment and local development tools, making it more versatile for full-stack development across multiple languages. The choice between the two depends on the specific needs of the project and the developer's preferred workflow.

Firebase SDK for Apple App Development

Pros of firebase-ios-sdk

  • Native iOS integration, optimized for Apple platforms
  • Direct access to Firebase services without network calls
  • Offline support and local caching capabilities

Cons of firebase-ios-sdk

  • Limited to iOS development, not cross-platform
  • Larger SDK size compared to firebase-tools
  • Requires more setup and configuration in Xcode

Code Comparison

firebase-ios-sdk (Swift):

import Firebase

FirebaseApp.configure()
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["name": "John"])

firebase-tools (JavaScript):

const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
db.collection('users').add({name: 'John'});

The firebase-ios-sdk provides a native Swift interface for iOS development, while firebase-tools offers a JavaScript-based approach for server-side and cross-platform development. The iOS SDK is more tightly integrated with the Apple ecosystem, providing better performance and offline capabilities. However, it's limited to iOS development, whereas firebase-tools can be used across various platforms and environments. The code examples demonstrate the syntax differences between the two, with firebase-ios-sdk using Swift and firebase-tools using JavaScript.

Firebase Android SDK

Pros of firebase-android-sdk

  • Specifically designed for Android app development, offering optimized performance and native integration
  • Provides direct access to Firebase services within Android applications
  • Includes Android-specific features and APIs not available in firebase-tools

Cons of firebase-android-sdk

  • Limited to Android platform, lacking cross-platform support
  • Requires more setup and configuration compared to the CLI-based firebase-tools
  • May have a steeper learning curve for developers new to Android development

Code Comparison

firebase-android-sdk:

// Initialize Firebase
FirebaseApp.initializeApp(this)

// Access Firestore
val db = FirebaseFirestore.getInstance()

firebase-tools:

# Initialize Firebase project
firebase init

# Deploy to Firebase
firebase deploy

Key Differences

  • firebase-android-sdk is a SDK for Android app development, while firebase-tools is a CLI for Firebase project management
  • firebase-android-sdk is used within Android apps, whereas firebase-tools is used for project setup, deployment, and management
  • firebase-android-sdk requires integration into Android project code, while firebase-tools is used from the command line

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Firebase CLI Actions Status Node Version NPM version

The Firebase Command Line Interface (CLI) Tools can be used to test, manage, and deploy your Firebase project from the command line.

  • Deploy code and assets to your Firebase projects
  • Run a local web server for your Firebase Hosting site
  • Interact with data in your Firebase database
  • Import/Export users into/from Firebase Auth

To get started with the Firebase CLI, read the full list of commands below or check out the documentation.

Installation

Node Package

You can install the Firebase CLI using npm (the Node Package Manager). Note that you will need to install Node.js and npm. Installing Node.js should install npm as well.

To download and install the Firebase CLI run the following command:

npm install -g firebase-tools

This will provide you with the globally accessible firebase command.

Standalone Binary

The standalone binary distribution of the Firebase CLI allows you to download a firebase executable without any dependencies.

To download and install the CLI run the following command:

curl -sL firebase.tools | bash

Commands

The command firebase --help lists the available commands and firebase <command> --help shows more details for an individual command.

If a command is project-specific, you must either be inside a project directory with an active project alias or specify the Firebase project id with the -P <project_id> flag.

Below is a brief list of the available commands and their function:

Configuration Commands

CommandDescription
loginAuthenticate to your Firebase account. Requires access to a web browser.
logoutSign out of the Firebase CLI.
login:ciGenerate an authentication token for use in non-interactive environments.
login:addAuthorize the CLI for an additional account.
login:listList authorized CLI accounts.
login:useSet the default account to use for this project
useSet active Firebase project, manage project aliases.
openQuickly open a browser to relevant project resources.
initSetup a new Firebase project in the current directory. This command will create a firebase.json configuration file in your current directory.
helpDisplay help information about the CLI or specific commands.

Append --no-localhost to login (i.e., firebase login --no-localhost) to copy and paste code instead of starting a local server for authentication. A use case might be if you SSH into an instance somewhere and you need to authenticate to Firebase on that machine.

Project Management Commands

CommandDescription
apps:createCreate a new Firebase app in a project.
apps:listList the registered apps of a Firebase project.
apps:sdkconfigPrint the configuration of a Firebase app.
projects:addfirebaseAdd Firebase resources to a Google Cloud Platform project.
projects:createCreate a new Firebase project.
projects:listPrint a list of all of your Firebase projects.

Deployment and Local Emulation

These commands let you deploy and interact with your Firebase services.

CommandDescription
emulators:execStart the local Firebase emulators, run a test script, then shut down the emulators.
emulators:startStart the local Firebase emulators.
deployDeploys your Firebase project. Relies on firebase.json configuration and your local project folder.
serveStart a local server with your Firebase Hosting configuration and HTTPS-triggered Cloud Functions. Relies on firebase.json.
setup:emulators:databaseDownloads the database emulator.
setup:emulators:firestoreDownloads the firestore emulator.

App Distribution Commands

CommandDescription
appdistribution:distributeUpload a distribution.

Auth Commands

CommandDescription
auth:importBatch importing accounts into Firebase from data file.
auth:exportBatch exporting accounts from Firebase into data file.

Detailed doc is here.

Realtime Database Commands

CommandDescription
database:getFetch data from the current project's database and display it as JSON. Supports querying on indexed data.
database:setReplace all data at a specified location in the current project's database. Takes input from file, STDIN, or command-line argument.
database:pushPush new data to a list at a specified location in the current project's database. Takes input from file, STDIN, or command-line argument.
database:removeDelete all data at a specified location in the current project's database.
database:updatePerform a partial update at a specified location in the current project's database. Takes input from file, STDIN, or command-line argument.
database:profileProfile database usage and generate a report.
database:instances:createCreate a realtime database instance.
database:instances:listList realtime database instances.
database:settings:getRead the realtime database setting at path
database:settings:setSet the realtime database setting at path.

Extensions Commands

CommandDescription
extDisplay information on how to use ext commands and extensions installed to your project.
ext:configureConfigure an existing extension instance.
ext:infoDisplay information about an extension by name (extensionName@x.y.z for a specific version)
ext:installInstall an extension.
ext:listList all the extensions that are installed in your Firebase project.
ext:uninstallUninstall an extension that is installed in your Firebase project by Instance ID.
ext:updateUpdate an existing extension instance to the latest version.

Cloud Firestore Commands

CommandDescription
firestore:deleteDelete documents or collections from the current project's database. Supports recursive deletion of subcollections.
firestore:indexesList all deployed indexes from the current project.

Cloud Functions Commands

CommandDescription
functions:logRead logs from deployed Cloud Functions.
functions:listList all deployed functions in your Firebase project.
functions:config:setStore runtime configuration values for the current project's Cloud Functions.
functions:config:getRetrieve existing configuration values for the current project's Cloud Functions.
functions:config:unsetRemove values from the current project's runtime configuration.
functions:config:cloneCopy runtime configuration from one project environment to another.
functions:secrets:setCreate or update a secret for use in Cloud Functions for Firebase.
functions:secrets:getGet metadata for secret and its versions.
functions:secrets:accessAccess secret value given secret and its version. Defaults to accessing the latest version.
functions:secrets:pruneDestroys unused secrets.
functions:secrets:destroyDestroy a secret. Defaults to destroying the latest version.
functions:deleteDelete one or more Cloud Functions by name or group name.
functions:shellLocally emulate functions and start Node.js shell where these local functions can be invoked with test data.

Hosting Commands

CommandDescription
hosting:disableStop serving Firebase Hosting traffic for the active project. A "Site Not Found" message will be displayed at your project's Hosting URL after running this command.

Remote Config Commands

CommandDescription
remoteconfig:getGet a Firebase project's Remote Config template.
remoteconfig:versions:listGet a list of the most recent Firebase Remote Config template versions that have been published.
remoteconfig:rollbackRoll back a project's published Remote Config template to the version provided by --version_number flag.

Use firebase:deploy --only remoteconfig to update and publish a project's Firebase Remote Config template.

Authentication

General

The Firebase CLI can use one of four authentication methods listed in descending priority:

  • User Token - DEPRECATED: this authentication method will be removed in a future major version of firebase-tools; use a service account to authenticate instead - provide an explicit long-lived Firebase user token generated from firebase login:ci. Note that these tokens are extremely sensitive long-lived credentials and are not the right option for most cases. Consider using service account authorization instead. The token can be set in one of two ways:
    • Set the --token flag on any command, for example firebase --token="<token>" projects:list.
    • Set the FIREBASE_TOKEN environment variable.
  • Local Login - run firebase login to log in to the CLI directly as yourself. The CLI will cache an authorized user credential on your machine.
  • Service Account - set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to the path of a JSON service account key file. For more details, see Google Cloud's Getting started with authentication guide.
  • Application Default Credentials - if you use the gcloud CLI and log in with gcloud auth application-default login, the Firebase CLI will use them if none of the above credentials are present.

Multiple Accounts

By default firebase login sets a single global account for use on all projects. If you have multiple Google accounts which you use for Firebase projects you can authorize multiple accounts and use them on a per-project or per-command basis.

To authorize an additonal account for use with the CLI, run firebase login:add. You can view the list of authorized accounts with firebase login:list.

To set the default account for a specific Firebase project directory, run firebase login:use from within the directory and select the desired account. To check the default account for a directory, run firebase login:list and the default account for the current context will be listed first.

To set the account for a specific command invocation, use the --account flag with any command. For example firebase --account=user@domain.com deploy. The specified account must have already been added to the Firebase CLI using firebase login:add.

Cloud Functions Emulator

The Cloud Functions emulator is exposed through commands like emulators:start, serve and functions:shell. Emulated Cloud Functions run as independent node processes on your development machine which means they have their own credential discovery mechanism.

By default these node processes are not able to discover credentials from firebase login. In order to provide a better development experience, when you are logged in to the CLI through firebase login we take the user credentials and construct a temporary credential that we pass into the emulator through GOOGLE_APPLICATION_CREDENTIALS. We only do this if you have not already set the GOOGLE_APPLICATION_CREDENTIALS environment variable yourself.

Using behind a proxy

The CLI supports HTTP(S) proxies via environment variables. To use a proxy, set the HTTPS_PROXY or HTTP_PROXY value in your environment to the URL of your proxy (e.g. HTTP_PROXY=http://127.0.0.1:12345).

Using with CI Systems

The Firebase CLI requires a browser to complete authentication, but is fully compatible with CI and other headless environments.

Complete the following steps to run Firebase commands in a CI environment. Find detailed instructions for each step in Google Cloud's Getting started with authentication guide.

  1. Create a service account and grant it the appropriate level of access to your project.
  2. Create a service account key (JSON file) for that service account.
  3. Store the key file in a secure, accessible way in your CI system.
  4. Set GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json in your CI system when running Firebase commands.

To disable access for the service account, find the service account for your project in the Google Cloud Console, and then either remove the key, or disable or delete the service account.

Using as a Module

The Firebase CLI can also be used programmatically as a standard Node module. Each command is exposed as a function that takes positional arguments followed by an options object and returns a Promise.

So if we run this command at our command line:

$ firebase --project="foo" apps:list ANDROID

That translates to the following in Node:

const client = require("firebase-tools");
client.apps
  .list("ANDROID", { project: "foo" })
  .then((data) => {
    // ...
  })
  .catch((err) => {
    // ...
  });

The options object must be the very last argument and any unspecified positional argument will get the default value of "". The following two invocations are equivalent:

const client = require("firebase-tools");

// #1 - No arguments or options, defaults will be inferred
client.apps.list();

// #2 - Explicitly provide "" for all arguments and {} for options
client.apps.list("", {});

Note: when used in a limited environment like Cloud Functions, not all firebase-tools commands will work programatically because they require access to a local filesystem.

NPM DownloadsLast 30 Days