title: How to write to firestore emulator?
body: <p>I am developing a firebase cloud function that writes to a firestore database.</p>
  
  <p>During development I want the function to write to a local database. So I've started a firestore emulator. But the data is still written to the actual database.</p>
  
  <p>How can I configure the cloud functions to use the local database?</p>
  
  <p>This is my setup:</p>
  
  <pre class="lang-js prettyprint-override"><code>import * as functions from 'firebase-functions';
  import * as cors from "cors";
  import * as admin from "firebase-admin";
  
  const REGION = "europe-west1";
  const COLLECTION_CONTACT_FORM = "contact_form";
  
  const serviceAccount = require("../keys/auth-key.json");
  admin.initializeApp({
      credential: admin.credential.cert(serviceAccount)
  });
  
  const corsMiddleware = cors({origin: true});
  
  export const sendContactForm = functions.region(REGION).https.onRequest((request, response) =&gt; corsMiddleware(request, response, async () =&gt; {
      let {text} = request.body;
      let result = await admin.firestore().collection(COLLECTION_CONTACT_FORM).add({text});
      response.send((result.id));
  }));
  </code></pre>
  
  <p>This is the console output when starting the emulator:</p>
  
  <pre><code>[1] i  firestore: Serving WebChannel traffic on at http://localhost:8081
  [1] i  firestore: Emulator logging to firestore-debug.log
  [1] ✔  functions: Emulator started at http://localhost:5000
  [1] ✔  firestore: Emulator started at http://localhost:8080
  [1] i  functions: Watching "path/functions" for Cloud Functions...
  [1] ⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to path/keys/auth-key.json. Non-emulated services will access production using these credentials. Be careful!
  [1] ✔  functions[sendContactForm]: http function initialized (http://localhost:5000/project/europe-west1/sendContactForm).
  </code></pre>
  
  <p>When triggering the local endpoint, the production database is written to.</p>