在Node.JS中关闭Firebase连接 [英] Closing a firebase connection in Node.JS

查看:144
本文介绍了在Node.JS中关闭Firebase连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的node.JS命令行脚本,以使用Javascript API与Firebase进行交互。我希望该工具关闭Firebase连接,并在完成交互后终止。

下面是一些示例代码,显示了我正在尝试实现的内容:

  var Firebase = require('firebase'); 
var myRootRef =新的Firebase('https://myprojectname.firebaseIO-demo.com/');
myRootRef.set('It's working!');

一个可能的解决方案是添加一个回调函数并调用process.exit():

var Firebase = require('firebase');
var myRootRef =新的Firebase('https://myprojectname.firebaseIO-demo.com/');
myRootRef.set(It's working!,function(){
process.exit(0);
});

然而,我希望有一个比强制进程终止process.exit更优雅的解决方案()。



有什么想法? 我并不热衷于强迫断开与 process.exit(0)要么..因为我只需要数据持久性(不是实时功能)我使用 REST API ..我发现普通HTTPS的速度是官方firebase npm模块的两倍..

  var https = require(https),
someData = {some:data};
$ b $ var req = https.request({
hostname:myprojectname.firebaseio.com,
method:POST,
path:/.json
});
req.end(JSON.stringify(someData));


I'm trying to create a simple node.JS command-line script to interact with Firebase using their Javascript API. I want the tool to close the Firebase connection and terminate once it has finished it's interaction.

Here is some sample code showing what I am trying to achieve:

var Firebase = require('firebase');
var myRootRef = new Firebase('https://myprojectname.firebaseIO-demo.com/');
myRootRef.set('It's working!');

One possible solution would be adding a callback and calling process.exit():

var Firebase = require('firebase');
var myRootRef = new Firebase('https://myprojectname.firebaseIO-demo.com/');
myRootRef.set("It's working!", function() { 
    process.exit(0); 
});

However, I would love to have a more elegant solution than forcing the process to terminate with process.exit().

Any ideas?

解决方案

i'm not keen on forcing disconnect with process.exit(0) either.. as i only require data persistence (not real-time features) i use the REST API.. I find plain HTTPS twice as fast as the official firebase npm module..

var https = require("https"),
    someData = { some: "data" };

var req = https.request({ 
    hostname: "myprojectname.firebaseio.com", 
    method: "POST", 
    path: "/.json"
});
req.end(JSON.stringify(someData));

这篇关于在Node.JS中关闭Firebase连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆