title: What's the right way to import a firebase module from another js file?
body: <p>I'm trying to develop a firebase webapp with an auth method.</p>
  
  <p>In my function folder I have the file <code>index.js</code> and <code>auth.js</code>, I've Imported the firebase method inside the <code>index</code> with:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const firebase = require('firebase-admin');
  const express = require('express');
  const engines = require('consolidate');
  const userService = require('./auth');
  
  const firebaseApp = firebase.initializeApp(
      functions.config().firebase
  );
  </code></pre>
  
  <p>and the index file works just fine, the problem is that I need <code>firebase</code> also in the <code>auth</code> file, but if I write at the top of the file:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const firebase = require('firebase-admin');
  
  const firebaseApp = firebase.initializeApp(
      functions.config().firebase
  );
  </code></pre>
  
  <p>It through me error saying:
  <code>The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once</code></p>
  
  <p>So, I've tried to get the firebase from the <code>index</code> like so:
  <code>const firebase = require('./index');</code>
  But it show me this error: <code>firebase.auth is not a function</code></p>
  
  <p>(I call <code>firebase.auth().signInWithEmailAndPassword(email, password)</code> in a function in order to signIn)</p>
  
  <p>The only method to make it work is to write:</p>
  
  <pre><code>const firebase = require("firebase");
  var config = {
      apiKey: "*****",
      authDomain: "***.com",
      databaseURL: "https://***.com",
      projectId: "****",
      storageBucket: "v***.com",
      messagingSenderId: "*****"
    };
      firebase.initializeApp(config);
  
  const db = firebase.firestore();
  </code></pre>
  
  <p>But I get errors when I try to deploy to firebase, so I'm pretty sure it's not the correct way to do it.</p>
  
  <p>I guess I'm messing with the imports, what should I do?</p>