Last active
May 1, 2024 12:56
-
-
Save hwindo/4620a33ee3ca0512f3c99317af8bda49 to your computer and use it in GitHub Desktop.
Checking firebase initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// basic checking | |
// if (firebase.apps.length === 0) { | |
// firebase.initializeApp({ | |
// // ... firebase config | |
// }) | |
// } | |
// node module | |
// example named file: firebase.js | |
/** | |
* Firebase | |
* singleton design pattern | |
*/ | |
var firebase = require('firebase'); | |
var config = { | |
apiKey: "___" | |
// ... and so on (firebase config) | |
}; | |
firebase.initializeApp(config); | |
function getInstance() { | |
console.log('getting firebase instance'); | |
if (firebase.appslength === 0) { | |
console.log('firebase not yet initialized, initializing, firebase apps length:', firebase.apps.length, firebase.apps); | |
firebase.initializeApp(config); | |
} else { | |
console.log('firebase already initialized, use existing', firebase.apps.length, firebase.apps); | |
} | |
return firebase; | |
} | |
module.exports = { | |
getInstance: getInstance | |
}; | |
// usage | |
// var firebase = require('./firebase').getInstance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment