title: How can I use shared firestore instance on express?
body: <p>I have a Firebase Functions with Express app and I would like to use the Firestore instance on multiple controllers. So I created a simple service:</p>
  
  <p><strong>./services/firebase.serivce.ts</strong></p>
  
  <pre><code>  admin.initializeApp(functions.config().firebase);
    const firestore = admin.firestore();
    export const db = firestore;
  </code></pre>
  
  <p>Then in my controller</p>
  
  <p><strong>./controllers/test.ts</strong></p>
  
  <pre><code>import { db } from './../services/firebase.service';
  ...
  
  const collection = db.collection('contacts');
  const router = express.Router();
  
  router.post('/', (req, res) =&gt; {
  ...
  </code></pre>
  
  <p>and the <code>app.js</code></p>
  
  <pre><code> import { TestController } from './controllers/test'
   ...
  
    app.use('/contact', TestController);
    export const api = functions.https.onRequest(app);
  </code></pre>
  
  <p>But Im getting the error:</p>
  
  <blockquote>
    <p>The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.</p>
  </blockquote>
  
  <p>And if I try to <code>initializeApp()</code> in all my controllers, I get a message saying that the app already exists. </p>
  
  <p>What can I do to share the same instance for multiple files?</p>