title: initializeApp when adding firebase to app and to server
body: <p>I'm using firebase for auth and db, and AWS lambda for cloud functions. </p>
  
  <p>To add firebase to my JS project, I <code>initializeApp</code> with the firebase config as parameter, as documented here : <a href="https://firebase.google.com/docs/web/setup" rel="noreferrer">https://firebase.google.com/docs/web/setup</a>.</p>
  
  <p>As documented here : <a href="https://firebase.google.com/docs/admin/setup" rel="noreferrer">https://firebase.google.com/docs/admin/setup</a>, I also need to <code>initializeApp</code> in my lambda function.</p>
  
  <p>Something as follows here :</p>
  
  <pre><code>const admin = require('firebase-admin');
  const serviceAccount = require('../path/to/service-account.json');
  
  const firebaseAdmin = admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "dB_URL"
  });
  </code></pre>
  
  <p>The credentials come from the firebase-admin library, so I cannot add this to my web firebase config. So, I need to initialize twice.</p>
  
  <p>However, if I proceed like this, the server will throw an error :</p>
  
  <blockquote>
    <p>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.But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.</p>
  </blockquote>
  
  <p>Am I missing something here ? What's the best practice ? I'm confused.</p>
  
  <p>Someone faced the same issue before it seems : <a href="https://stackoverflow.com/questions/51522280/use-firebase-sdk-with-netlify-lambda-functions">Use Firebase SDK with Netlify Lambda Functions</a></p>
  
  <p>What worked for this user was to use the REST API as documented here : <a href="https://firebase.google.com/docs/projects/api/workflow_set-up-and-manage-project" rel="noreferrer">https://firebase.google.com/docs/projects/api/workflow_set-up-and-manage-project</a></p>
  
  <p>The documentation says it's in beta though.</p>
  
  <p>Thanks for your kind help</p>