title: Using firebase-admin. What are service account credentials used for?
body: <p>I'm building a cloud function to get some documents and generate an HTML response.</p>
  
  <p>And right now what I have is:</p>
  
  <p><strong>myFunction.js</strong></p>
  
  <pre><code>import * as admin from 'firebase-admin';
  import serviceAccount from './someServiceAccountKey.json';
  
  // OPTION #1  &lt;-----
  
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://myfirebaseproject.firebaseio.com"
  });
  
  // OPTION #2 &lt;------
  
  admin.initializeApp();
  
  // FUNCTION &lt;------
  
  async function(req,res) {
  
    const docSnapshot = await admin.firestore().collection('someCollection').doc('someDoc').get();
    // AND SO ON...
  }
  </code></pre>
  
  <p>At some point I've created that serviceAccount key (I don't remember from which tutorial) and I've been using on my functions to "grant access" to the <code>firebase-admin</code> (as in <strong>OPTION #1</strong> from the code above). Because I thought I needed to.</p>
  
  <p>But I've found out that even without any initializing parameter or serviceAccount credential (as in <strong>OPTION #2</strong> from the code above), I can initialize the <code>firebase-admin</code> and access my firebase project resources (like Firestore) without any issues.</p>
  
  <p>And I can do this on deployed functions, which makes sense, since they are inside the Firebase project's cloud environment, and if they were deployed, they should have access to the project's resources, without the need for a service account, right?</p>
  
  <p>But I also found out that I can do this in my Node.js local environment. By calling the function with <code>npx babel-node myFunction.js</code> (using babel node to transpile and execute). The function is able to access and query my Firestore (on-line data, this is not the Firestore emulator) without any issues.</p>
  
  <p>Where is my local environment getting permission to access my project's resources from? Is it from the <code>firebase-tools</code> that is installed and logged in my project?</p>
  
  <p>If I don't need them in both cases. What are service accounts mainly used for?</p>