Catch up on everything we announced at this year's Firebase Summit. Learn more

Alternative ways to add Firebase to your JavaScript project

For most Firebase Web apps we strongly recommend using SDK version 9 via npm. However, for users with special requirements, Firebase provides alternative ways to add the SDK. This page provides detailed setup instructions for these alternative methods:

  • CDN (content delivery network)
  • npm for Node.js apps

Using these methods, you can add any of the available libraries for version 9 to your app.

From the CDN

You can configure partial import of the Firebase JavaScript SDK and only load the Firebase products that you need. Firebase stores each library of the Firebase JavaScript SDK on our global CDN (content delivery network).

  1. To include only specific Firebase products (for example, Authentication and Cloud Firestore), add the following script to the bottom of your <body> tag, but before you use any Firebase services:

    <body>
      <!-- Insert this script at the bottom of the HTML, but before you use any Firebase services -->
    
      <script type="module">
        import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js'
    
        // If you enabled Analytics in your project, add the Firebase SDK for Google Analytics
        import { analytics } from 'https://www.gstatic.com/firebasejs/9.6.0/firebase-analytics.js'
    
        // Add Firebase products that you want to use
        import { auth } from 'https://www.gstatic.com/firebasejs/9.6.0/firebase-auth.js'
        import { firestore } from 'https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore.js'
      </script>
    </body>
    
  2. Initialize Firebase in your app:

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

Node.js apps

  1. Install the Firebase JavaScript SDK:

    1. If you don't already have a package.json file, create one by running the following command from the root of your JavaScript project:

      npm init
    2. Install the firebase npm package and save it to your package.json file by running:

      npm install --save firebase@9.6.0
  2. Use one of the following options to use the Firebase module in your app:

    • You can require modules from any JavaScript file

      To include only specific Firebase products (like Authentication and Cloud Firestore):

      // Firebase App (the core Firebase SDK) is always required and
      // must be listed before other Firebase SDKs
      var firebase = require("firebase/app");
      
      // Add the Firebase products that you want to use
      require("firebase/auth");
      require("firebase/firestore");
      


    • You can use ES2015 to import modules

      To include only specific Firebase products (like Authentication and Cloud Firestore):

      // Firebase App (the core Firebase SDK) is always required and
      // must be listed before other Firebase SDKs
      import firebase from "firebase/app";
      
      // Add the Firebase services that you want to use
      import "firebase/auth";
      import "firebase/firestore";
      
  3. Initialize Firebase in your app:

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