Hosting Setup
Last updated
Was this helpful?
Last updated
Was this helpful?
Using the ionic extension Locate Capacitor, under that select build after the build is done, select Sync.
You can use npm
(the Node Package Manager) to install the Firebase CLI.
Install using (the Node Version Manager). Installing Node.js automatically installs the npm
command tools.Note: The Firebase CLI requires Node.js v8.0.0 or later. Some Firebase services might require specific versions of Node.js, so check each Firebase service's getting started page for any specific Node.js requirements.
Install the Firebase CLI via npm
by running:
This command enables the globally available firebase
command.Note: If the npm install -g firebase-tools
command fails, you might need to .
Continue to .
After installing the CLI, you must authenticate. Then you can confirm authentication by listing your Firebase projects.
Sign into Firebase using your Google account:
This command connects your local machine to Firebase and grants you access to your Firebase projects.Note: You can also .
Test that the CLI is properly installed and accessing your account by listing your Firebase projects:
The displayed list should be the same as the Firebase projects listed in the .
Generally, you want to use the most up-to-date Firebase CLI version.In many cases, new features and bug fixes are available only with the latest version of the Firebase CLI. It's a good practice to frequently update the CLI to its latest version.
npm: Run npm install -g firebase-tools
The Firebase CLI requires a browser to complete authentication, but the CLI is fully compatible with CI and other headless environments.
Start the sign in process by running:
Visit the URL provided, then sign in using a Google account.
Store the output token in a secure but accessible way in your CI system.
Use this token when running firebase
commands; you have two options:
Store the token as the environment variable FIREBASE_TOKEN. Your system will automatically use the token.
Run all firebase
commands with the --token <token>
flag in your CI system.
The order of precedence for token loading is flag, environment variable, desired Firebase project.
Note: On any machine with the Firebase CLI installed, you can immediately revoke access for the specified token by running: firebase logout --token token
To initialize a new Firebase project, run the following command from within your app's directory:
Note: The firebase init
command does not create a new directory. If you're starting a new app, you must first make a directory, then run firebase init
from within that directory.
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.
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.
At the end of initialization, Firebase automatically creates and adds two files to the root of your local app directory:
firebase.json
fileThe following is an example firebase.json
file with default settings if you select Firebase Hosting, Cloud Firestore, and Cloud Functions for Firebase during initialization.
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:
View the static content for your Firebase-hosted app.
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:
To emulate HTTP functions only, use the following command:
By default, firebase serve
only responds to requests from localhost
. This means that you'll be able to access your hosted content from your computer's web browser but not from other devices on your network. If you'd like to test from other local devices, use the --host
flag:
The Firebase CLI manages deployment of code and assets to your Firebase project, including:
New releases of your Firebase Hosting sites
New, updated, or existing Cloud Functions for Firebase
Rules for Firebase Realtime Database
Rules for Cloud Storage for Firebase
Rules for Cloud Firestore
Indexes for Cloud Firestore
To deploy to a Firebase project, run the following command from your project directory:
It's not currently possible to roll back releases of security rules for Firebase Realtime Database, Cloud Storage for Firebase, or Cloud Firestore.
If you only want to deploy specific Firebase services or features, you can use a comma-separated list in a flag on the firebase deploy
command. For example, the following command deploys Firebase Hosting content and Cloud Storage security rules.
Flag syntax
Service or feature deployed
--only hosting
Firebase Hosting content
--only database
Firebase Realtime Database rules
--only storage
Cloud Storage for Firebase rules
--only firestore
Cloud Firestore rules and indexes
--only firestore:rules
Cloud Firestore rules
--only firestore:indexes
Cloud Firestore indexes
--only functions
Note: The --only rules
syntax used by older versions of the CLI is deprecated.
How you update the CLI version depends on your operating system and how you installed the CLI.
standalone binary: , then replace it on your system
On a machine with a browser, .
Print a new . The current CLI session will not be affected.
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 configuration file.
To set up a specific Firebase product for your project, refer to that product's documentation for setup information (for example, ). Note that you can always run firebase init
later to set up more Firebase products.
It's also possible to (such as a staging project and a production project) with the same project directory.
A configuration file that lists your project configuration.
A .firebaserc
file that stores your project .
The command creates a firebase.json
configuration file in the root of your project directory.
The firebase.json
file is required to 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 .
You can directly in the firebase.json
file. However, for other , 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 in the firebase.json
file.Note: If you run firebase init
again for any Firebase service, the command will overwrite the corresponding section of the firebase.json
file back to the default configuration for that service.
Use Cloud Functions to and you want to use your production (deployed) HTTP functions to emulate Hosting on a local URL.
By default, firebase deploy
creates a release for all deployable resources in your project directory. To deploy specific Firebase services or features, .
Note that to deploy resources from a project directory, the project directory must have a file. This file was automatically created for you by the command.
You can optionally add a comment to each of your deployments. This comment will display with the other deployment information on your project's . For example:
For Firebase Realtime Database, Cloud Storage for Firebase, and Cloud Firestore, you can define security rules either in your local project directory or in the .Note: When you , the rules defined in your project directory overwrite any existing rules in the Firebase console. So, if you choose to define or edit your security rules using the Firebase console, make sure that you also update the rules defined in your project directory.
Another option to avoid deployment conflicts is to and only define rules in the Firebase console.
It's possible (though unlikely) that you might exceed a quota that limits the rate or volume of your Firebase deployment operations. For example, when deploying very large numbers of functions, you might receive an HTTP 429 Quota
error message. To solve such issues, try or for specific Firebase services. For example, the quota called Write requests per 100 seconds per user might help to resolve the Cloud Functions 429
error cited above.
You can roll back a Firebase Hosting deployment from your project's by selecting the Rollback action for the desired release.
The following table lists the services and features available for partial deployment. The names in the flags correspond to the keys in your configuration file.
Cloud Functions for Firebase ( are possible)