title: Do i need to include admin.initializeApp(); in all my firebase cloud functions file (Typescript)?
body: <p>Question: If i'd like to use firebase services in separate function files, do i have to include <code>admin.initializeApp();</code> at the top of each file?</p>
  
  <p>What is the current best practice of doing this?</p>
  
  <p>I have a source folder containing 3 files</p>
  
  <ol>
  <li>auth.ts - admin.initializeApp is at the top of this file</li>
  <li>http.ts - Do i add it here if i want to use firebase services?</li>
  <li>index.ts</li>
  </ol>
  
  <p>My index.ts file is: </p>
  
  <pre><code>export { basicHTTP, advanceHTTP, api } from "./http";
  export { createUserRecord } from "./auth";
  </code></pre>
  
  <p>My auth.ts file uses the admin.firestore():</p>
  
  <pre><code>import * as functions from "firebase-functions";
  
  import * as admin from "firebase-admin";
  
  admin.initializeApp();
  
  const db = admin.firestore();
  
  export const createUserRecord = functions.auth
    .user()
    .onCreate((user, context) =&gt; {
      const userRef = db.doc(`users/${user.uid}`);
      return userRef.set({
        name: user.displayName,
        createdAt: context.timestamp,
        nickname: "bubba"
      });
    });
  </code></pre>
  
  <p>My http.ts file contains the following, what do i do if i want to use a firebase service within this function?: </p>
  
  <pre><code>import * as functions from "firebase-functions";
  
  import * as admin from "firebase-admin";
  
  // Express
  import * as express from "express";
  import * as cors from "cors";
  
  // Most basic http function
  
  export const basicHTTP = functions.https.onRequest((request, response) =&gt; {
    response.send("Hello from firebase");
  });
  
  export const advanceHTTP = functions.https.onRequest((request, response) =&gt; {
    const name = request.query.name;
  
    if (!name) {
      response.status(400).send("You must supply a name");
    }
  
    response.send(`Hi there ${name}`);
  });
  
  // Custom middleware
  
  const auth = (request, response, next) =&gt; {
    if (!request.header.authorization) {
      response.status(400).send("Unauthorized. Access denied");
    }
    next();
  };
  
  // Multi Route ExpressJS HTTP Function
  
  const app = express();
  
  app.use(cors({ origin: true }));
  
  app.use(auth);
  
  app.get("/cat", (request, response) =&gt; {
    response.send("Cat");
  });
  
  app.get("/dog", (request, response) =&gt; {
    response.send("dog");
  });
  
  export const api = functions.https.onRequest(app);
  </code></pre>