Ad

Where And When To Use Firebase Admin.app().delete()?

I'm new to using firebase and node.js and have a general question on where and when to use ' admin.app().delete() ' ?

I understand it's used to terminate access to the firebase app, but not sure I understand if you have to delete after every time you read/write to the realtime db? For example, in the code below should admin.app().delete() be used anywhere? And if it is used, will the app be initialized each time an export function (myFunc) in index.js is called?

\\index.js
admin.initializeApp(config.FIREBASE_CONFIG);
const foo = require('./foo');

exports.myFunc = functions.https.onRequest((req, res) => {
   foo.readFunction().then().catch();
   res.send('success!');
}

\\foo.js
exports.readFunction = function () {
const dbRef = admin.database().ref('/someCategory');

  var infoPromise = dbRef.once('value').then((snapshot) => {
    var info = snapshot.child('moreInfo').val();
    return info;
  }).catch((error) => {
    console.log('file read failed: ' + errorObject.code);
    throw error;
  });
  return infoPromise;
}
Ad

Answer

It doesn't make much sense to call App.delete() from within a Cloud Function. Cloud Functions are aggressively terminated and cleaned up by the underlying platform anyway. App.delete() is mainly useful in standalone applications and scripts to ensure graceful exit of the program.

Ad
source: stackoverflow.com
Ad