कंसोल पर जाएं

Firebase CLI Reference

The Firebase CLI (GitHub) provides a variety of tools for managing, viewing, and deploying to Firebase projects.

Before using the Firebase CLI, set up a Firebase project.

Install the Firebase CLI

The Firebase CLI (command line interface) requires Node.js and npm (the Node Package Manager).

  1. Install Node.js using one of the following options. Installing Node.js automatically installs npm.

    • For Mac/Linux, use nvm (the Node Version Manager).
    • For Windows, use nvm-windows.
  2. Install the Firebase CLI using npm by running:

    npm install -g firebase-tools

    This command installs the globally available firebase command. To update to the latest version of the Firebase CLI, re-run the same npm install command.

  3. Sign into Firebase using your Google account by running:

    firebase login

    This command connects your local machine to Firebase and grants you access to your Firebase projects.

  4. To test that authentication worked (and to list all of your Firebase projects), run the following command:

    firebase list

    The displayed list should be the same as the Firebase projects listed in the Firebase console.

Update to the latest CLI version

Make sure that you're using the most up-to-date Firebase CLI version by re-running the CLI installation command:

npm install -g firebase-tools

Initialize a Firebase project

Many common tasks performed using the CLI, such as deploying to a Firebase project, require a project directory. You establish a project directory using the firebase init command. A project directory is usually the same directory as your source control root, and after running firebase init, the directory contains a firebase.json configuration file.

To initialize a new Firebase project, run the following command from within your app's directory:

firebase init

The firebase init command steps you through setting up your project directory and some Firebase products. During project initialization, the Firebase CLI asks you to:

  • Select desired Firebase products then prompts you to set configurations for specific files for the selected products.

    To set up a specific Firebase product for your project, refer to that product's documentation for setup information (for example, Hosting). Note that you can always run firebase init later to set up more Firebase products.

  • Select a default Firebase project.

    This step associates the current project directory with a Firebase project so that project-specific commands (like firebase deploy) run against the appropriate Firebase project.

    It's also possible to associate multiple Firebase projects (such as a staging project and a production project) with the same project directory.

At the end of initialization, Firebase automatically creates and adds two files to the root of your local app directory:

  • A firebase.json configuration file that lists your project configuration.

  • A .firebaserc file that stores your project aliases.

The firebase.json file

The firebase init command creates a firebase.json configuration file in the root of your project directory.

The firebase.json file is required to deploy assets with the Firebase CLI because it specifies which files and settings from your project directory are deployed to your Firebase project. Since some settings can be defined in either your project directory or the Firebase console, make sure that you resolve any potential deployment conflicts.

You can configure most Firebase Hosting options directly in the firebase.json file. However, for other Firebase services that can be deployed with the Firebase CLI, the firebase init command creates specific files where you can define settings for those services, such as an index.js file for Cloud Functions. You can also set up predeploy or postdeploy hooks in the firebase.json file.

The following is an example firebase.json file with default settings if you select Firebase Hosting, Cloud Firestore, and Cloud Functions for Firebase during initialization.

  "hosting": {
    "public": "public",
    "ignore": [
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"

Serve and test your Firebase project locally

You can view and test your Firebase project on locally hosted URLs before deploying to production. If you only want to test select features, you can use a comma-separated list in a flag on the firebase serve command.

Run the following command from the root of your local project directory if you want to either:

firebase serve --only hosting

Run any of the following commands from your project directory to emulate your project using local HTTP functions.

  • To emulate HTTP functions and hosting for testing on local URLs, use either of the following commands:

    firebase serve
    firebase serve --only functions,hosting // uses a flag
  • To emulate HTTP functions only, use the following comman