GET STARTED WITH FIREBASE HOSTING

Get started with Firebase Hosting

Firebase Hosting gives you a fast, secure, and reliable way to host your app's static assets (HTML, CSS, JavaScript, media files, etc.) as well as to serve dynamic content and host microservices.
Our production-grade hosting is backed by a global content delivery network (CDN). Hosting serves your content over SSL, by default, and can be used with your own custom domain or on your project's free subdomains on web.app and firebaseapp.com.

Before you begin

Before you can set up Firebase Hosting, you need to create a Firebase project.

Step 1: 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

Step 2: Initialize your project

To connect your local project to your Firebase project, run the following command from the root of your local project directory:
firebase init
During project initialization, from the Firebase CLI prompts:
  1. Select to set up Hosting.
    If you want to set up other Firebase products for your project, refer to their documentation for setup information. Note that you can always run firebase init later to set up more Firebase products.
  2. Select a Firebase project to connect to your local project directory.
    The selected Firebase project is your "default" Firebase project for your local project directory. To connect additional Firebase projects to your local project directory, set up project aliases.
  3. Specify a directory to use as your public root directory.
    This directory contains all your publicly served static files, including your index.html file and any other assets that you want to deploy to Firebase Hosting.
    • The default for the public root directory is called public.
      • You can specify your public root directory now or you can specify it later in yourfirebase.json configuration file.
      • If you select the default and don't already have a directory called public, Firebase creates it for you.
    • If you don't already have a valid index.html file or 404.html file in your public root directory, Firebase creates them for you.
  4. Choose a configuration for your site.
    If you select to make a one-page app, then Firebase automatically adds rewrite configurations for you.
At the end of initialization, Firebase automatically creates and adds two files to the root of your local app directory:

Step 3: Deploy to your site

To deploy to your site, run the following command from the root of your local project directory:
firebase deploy
This command deploys a release to your Firebase project's default Hosting sites:
  • projectID.web.app
  • projectID.firebaseapp.com

Next steps

Now your site is ready to share with the world! You can also learn how to:
Also, take a look at the full documentation for the Firebase CLI.

Was this page helpful?

Comments

popular

firebase authentication using email/password

ABOUT SANTAN DHARM

HTML5 Tutorial

firebase realtime database