Below is a simple example how I am using firebase:
let firebase = require('firebase');
firebase.initializeApp({
serviceAccount: './config/firebase.json',
databaseURL: 'https://thenameofhedatabase.firebaseio.com'
});
let db = firebase.database();
...
...
The point is that after all code execution the db
object holds the node.js session. I do not want to call process.exit(0)
. So, what is the right way to close or dispose the db
object of the firebase?
The server. close() method stops the HTTP server from accepting new connections.
Try using: firebaseRef. off(); This will end your connection with firebase and stop communicating with the database.
By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache.
Firebase Hosting supports a REST API for advanced developers to build custom workflows, like deploying through a JavaScript app. We also have a Node. js module which you can import into your Node. js apps to build advanced functionality.
This is something that has been fixed in the version 3.4.1 of the JavaScript SDK.
firebase.database().goOffline()
now properly releases the database so the Node.js process can exit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With