[ Web Proxy ]
URL:
Viewing: https://firebase.google.com/support/guides/firebase-web [Back]  [Original]

Add Firebase to your JavaScript project  |  Firebase for web platforms Skip to main content
Overview Fundamentals AI Build Run Reference Samples
Firebase [Firebase]
Send feedback

Add Firebase to your JavaScript project Stay organized with collections Save and categorize content based on your preferences.

Follow this guide to use the Firebase JavaScript SDK in your web app or as a client for end-user access, for example, in a Node.js desktop or IoT application.

Step 1: Create a Firebase project and register your app

Before you can add Firebase to your JavaScript app, you need to create a Firebase project and register your app with that project. When you register your app with Firebase, you'll get a Firebase configuration object that you'll use to connect your app with your Firebase project resources.

Note: Upgrading from the version 8 Firebase SDK? Check out our upgrade guide.

Visit Understand Firebase Projects to learn more about Firebase projects and best practices for adding apps to projects.

Create a Firebase project

New to Firebase or Cloud

Follow these steps if you're new to Firebase or Google Cloud.
You can also follow these steps if you want to create a wholly new Firebase project (and its underlying Google Cloud project).

  1. Sign into the Firebase console.
  2. Click the button to create a new Firebase project.
  3. In the text field, enter a project name.

    If you're part of a Google Cloud org, you can optionally select which folder you create your project in.

    Your project name is used as a display name in Firebase interfaces, and Firebase auto-creates a unique project ID based on this project name. Note that you can optionally click the Edit icon now to set your preferred project ID, but you cannot change this ID after project creation. Learn about how Firebase uses the project ID.
  4. If prompted, review and accept the Firebase terms, then click Continue.
  5. (Optional) Enable AI assistance in the Firebase console (called "Gemini in Firebase"), which can help you get started and streamline your development process.
  6. (Optional) Set up Google Analytics for your project, which enables an optimal experience using these Firebase products: Firebase A/B Testing, Cloud Messaging, Crashlytics, In-App Messaging, and Remote Config (including Personalization).

    Either select an existing Google Analytics account or create a new account. If you create a new account, select your Analytics reporting location, then accept the data sharing settings and Google Analytics terms for your project.

    You can always set up Google Analytics later in the Integrations tab of your Project settings.
  7. Click Create project.

Firebase creates your project, provisions some initial resources, and enables important APIs. When the process completes, you'll be taken to the overview page for your Firebase project in the Firebase console.

Existing Cloud project

Follow these steps if you want to start using Firebase with an existing Google Cloud project. Learn more about and troubleshoot "adding Firebase" to an existing Google Cloud project.

  1. Sign into the Firebase console with the account that gives you access to the existing Google Cloud project.
  2. Click the button to create a new Firebase project.
  3. At the bottom of the page, click Add Firebase to Google Cloud project.
  4. In the text field, start entering the project name of the existing project, and then select the project from the displayed list.
  5. Click Open project.
  6. If prompted, review and accept the Firebase terms, then click Continue.
  7. (Optional) Enable AI assistance in the Firebase console (called "Gemini in Firebase"), which can help you get started and streamline your development process.
  8. (Optional) Set up Google Analytics for your project, which enables an optimal experience using these Firebase products: Firebase A/B Testing, Cloud Messaging, Crashlytics, In-App Messaging, and Remote Config (including Personalization).

    Either select an existing Google Analytics account or create a new account. If you create a new account, select your Analytics reporting location, then accept the data sharing settings and Google Analytics terms for your project.

    You can always set up Google Analytics later in the Integrations tab of your Project settings.
  9. Click Add Firebase.

Firebase adds Firebase to your existing project. When the process completes, you'll be taken to the overview page for your Firebase project in the Firebase console.

Register your app

After you have a Firebase project, you can register your web app with that project.

  1. In the center of the Firebase console's project overview page, click the Web icon () to launch the setup workflow.

    If you've already added an app to your Firebase project, click Add app to display the platform options.

  2. Enter your app's nickname.
    This nickname is an internal, convenience identifier and is only visible to you in the Firebase console.

  3. Click Register app.

  4. Follow the on-screen instructions to add and initialize the Firebase SDK in your app.

    You can also find more detailed instructions for adding, initializing, and using the Firebase SDK in the next steps of this getting started page.

If you don't already have a JavaScript project and just want to try out a Firebase product, you can download one of our quickstart samples.

Step 2: Install the SDK and initialize Firebase

This page describes setup instructions for the modular API for the Firebase JavaScript SDK, which uses a JavaScript Module format.

This workflow uses npm and requires module bundlers or JavaScript framework tooling because the modular API is optimized to work with module bundlers to eliminate unused code (tree-shaking) and decrease SDK size.

Note: Using the modular API is strongly recommended, especially for production apps. If you need support for calling the API in other ways, like window.firebase, see Upgrade from the namespaced API to the modular API or Alternative ways to add Firebase.
  1. Install Firebase using npm:

    npm install firebase
  2. Initialize Firebase in your app and create a Firebase App object:

    import { initializeApp } from 'firebase/app';
    
    // TODO: Replace the following with your app's Firebase configuration
    const firebaseConfig = {
      //...
    };
    
    const app = initializeApp(firebaseConfig);

    A Firebase App is a container-like object that stores common configuration and shares authentication across Firebase services. After you initialize a Firebase App object in your code, you can add and start using Firebase services.

    If your app includes dynamic features based on server-side rendering (SSR), you'll need to take some additional steps to ensure that your configuration persists across server rendering and client rendering passes. In your server logic, implement the FirebaseServerApp interface to optimize your app's session management with service workers.

    Do you use ESM and want to use browser modules? Replace all your import lines to use the following pattern:
    import { } from 'https://www.gstatic.com/firebasejs/12.17.1/firebase-SERVICE.js'
    (where SERVICE is an SDK name such as firebase-firestore).

    Using browser modules is a quick way to get started, but we recommend using a module bundler for production.

Step 3: Access Firebase in your app

Firebase services (like Cloud Firestore, Authentication, Realtime Database, Remote Config, and more) are available to import within individual sub-packages.

The example below shows how you could use the Cloud Firestore Lite SDK to retrieve a list of data.

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, getDocs } from 'firebase/firestore/lite';
// Follow this pattern to import other Firebase services
// import { } from 'firebase/<service>';

// TODO: Replace the following with your app's Firebase configuration
const firebaseConfig = {
  //...
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

// Get a list of cities from your database
async function getCities(db) {
  const citiesCol = collection(db, 'cities');
  const citySnapshot = await getDocs(citiesCol);
  const cityList = citySnapshot.docs.map(doc => doc.data());
  return cityList;
}

Step 4: Use a module bundler (webpack/Rollup) for size reduction

Note: You can skip this step if you are using a JavaScript framework CLI tool like the Angular CLI, Next.js, Vue CLI, or Create React App. For more information, check out our guide on module bundling.

The Firebase JavaScript SDK is designed to work with module bundlers to remove any unused code (tree-shaking). We strongly recommend using this approach for production apps. Tools such as the Angular CLI, Next.js, Vue CLI, or Create React App automatically handle module bundling for libraries installed through npm and imported into your codebase.

For more information, see our guide Using module bundlers with Firebase.

Available Firebase services for web

Now that you're setup to use Firebase, you can start adding and using any of the following available Firebase services in your web app.

The following commands show how to import Firebase libraries installed locally with npm. For alternative import options, see the available libraries documentation.

1 Firebase AI Logic was formerly called "Vertex AI in Firebase" with the package firebase/vertexai.

2 Firebase SQL Connect was formerly called "Firebase Data Connect".

Next steps

Learn about Firebase:

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-19 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-19 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page