Function stops before promise returned from Firebase


I am using a netlify function to write an entry to Firebase Firestore whenever someone sent his/ her email in the contact form. In my tests the lambda-function is reached and while using netlify dev on my local machine firebase firestore is also reached perfectly and the data added to the database.
Using the lambda-function on the webserver the end of the promise never gets reached. I assume the lambda-function stops before adding the data is executed?

This is my lambda-function:
const express = require(“express”);
const serverless = require(“serverless-http”);
const admin = require(“firebase-admin”);

let serviceAccount = require("./key.json")
if (admin.apps.length === 0) {
    credential: admin.credential.cert(serviceAccount),
    databaseURL: ""
let db = admin.firestore();

function upload_request(in_file) {
  console.log("reached: " +;

  let docRef = db.collection('requests').doc(;
      date: new Date().toLocaleString()
    .then(function () {
      console.log("Document successfully written!");
      return 0;
    .catch(function (error) {
      console.error("Error writing document: ", error);
      return 0;

// Express
const app = express();
const router = express.Router();

router.get("/", (req, res) => {
  res.send('This route only takes POST requests.')
});'/', function (req, res) {
  var data = JSON.parse(req.body)
  res.send("Send POST worked.")

app.use('/.netlify/functions/send_upload', router);

module.exports.handler = serverless(app);

This is the output that is logged in the lambda-function:

7:04:56 AM: 2020-04-13T05:04:56.358Z	c2e5b672-56b9-44b5-84d4-126e18db590a	 INFO	reached:
7:04:56 AM: Duration: 339.92 ms	Memory Usage: 112 MB	Init Duration: 716.31 ms	

Am I correct that Firebase might not work because the end of the promise is never reached?

Thanks for your help, I have no idea what to do right now!


So the function upload_request will return a promise as well. You’ll have to make sure that function resolves the promise. I don’t know how to do it using the chaining syntax but for async/await, upload_request and the callback function for your post route will need to both be an async function to make sure the promise is resolved before they try returning. Hope that helps.