The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services. at FirebaseAppError

You should just call admin.initializeApp() at the global scope of your code. Don't pass any parameters to accept the default service account, which should have permission to read and write your Cloud Firestore database.


This might sound like crazy, But I had the same issue. Then I've changed my "admin.initializeApp();" place like below. Then it works.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const app = express();
//put here.
admin.initializeApp();

const db = admin.firestore();

const firebaseConfig = {
// config data
};

const firebase = require('firebase');

firebase.initializeApp(firebaseConfig);

word of advice, sometimes this comes even if you initialized the app properly, at that point just check whether your db instance is placed inside the function not global.

#nodejs

var db = admin.database();//inside function