Getting reoriented after a long time since my last firestore project. Why does this script take an extra 60-90s — after the output — to complete? It works properly except for the mysterious ending…
import { initializeApp } from "firebase/app";
import { getFirestore, collection, query, getDocs } from "firebase/firestore";
const firebaseConfig = {
// my config
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
async function getSomeFirestoreData() {
try {
const ref = collection(db, "MyCollection");
const q = query(ref);
const querySnapshot = await getDocs(q);
querySnapshot.forEach(doc => {
console.log(doc.id, " => ", doc.data());
});
return "done"
} catch (e) {
console.log(e); // we don't get here
}
}
getSomeFirestoreData().then(r => {
console.log(r); // we get here fast (fast enough)
process.exit(); // terminates fast with this, but I shouldn't need it
});
After a recent install, package.json:
"node_modules/@firebase/firestore": {
"version": "4.6.1",
...
I see my doc data after a very reasonable delay and I see “done” immediately. Without the explicit exit, node doesn’t terminate for another minute and a half. Why?