Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close firebase connection in node.js

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?

like image 379
Andrei Tarutin Avatar asked Jul 06 '16 11:07

Andrei Tarutin


People also ask

How do I close a node JS connection?

The server. close() method stops the HTTP server from accepting new connections.

How do I close a Firebase database?

Try using: firebaseRef. off(); This will end your connection with firebase and stop communicating with the database.

Can I use Firebase offline?

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.

Can Firebase be used with node js?

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.


1 Answers

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.

like image 163
agregoire Avatar answered Oct 03 '22 02:10

agregoire