Search code examples
node.jsfirebasefirebase-realtime-databasenodes

Firebase removing the initialized DB once data is been pushed


How to remove the initialized firebase once the CRUD operation is completed? In my scenario I have to initialize the Secondary firebase dynamically based on particular requirements to do read/write operation, with below code

firebase.initializeApp(config, "Secondary");

when I run first time after server start, its initializing the required firebase with name as secondary, but If I try to rerun for next config, data for Secondary is still exist so ending up with error saying "FirebaseError: Firebase: Firebase App named 'Secondary' already exists". Found these data are part of the app, so tried removing it using firebase.apps.remove(), tried to pop the last index on apps array but that's not working as well. Is there a way I can remove the secondary instance of firebase that is getting initialized (I still need the default instance of the firebase).


Solution

  • Below code fixes by deleting the individual firebase initialized

      let client = firebase.initializeApp(config, "Secondary");
    
        client.delete().then(function () {
             console.log("Delete ", firebase.apps)
          }, (err => {
            console.log("error", err);
         }));