简体   繁体   English

如何在node.js中关闭firebase连接

[英]How to close firebase connection in node.js

Below is a simple example how I am using firebase: 下面是我使用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. 关键是在所有代码执行之后, db对象保存node.js会话。 I do not want to call process.exit(0) . 我不想调用process.exit(0) So, what is the right way to close or dispose the db object of the firebase? 那么,关闭或处理firebase的db对象的正确方法是什么?

This is something that has been fixed in the version 3.4.1 of the JavaScript SDK . 这是已在JavaScript SDK 3.4.1版中修复的内容

firebase.database().goOffline() now properly releases the database so the Node.js process can exit. firebase.database().goOffline()现在可以正确释放数据库,以便Node.js进程可以退出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM