节点进程不会在firebase之后退出一次 [英] node process doesn't exit after firebase once

查看:81
本文介绍了节点进程不会在firebase之后退出一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用node.js和npm firebase。

  var firebase = require('firebase'); 
var blahFirebase =新的firebase('https://myfirebase.firebaseIO.com/blah');
blahFirebase.once('value',function(snapshot){
//
});

为什么在读完数据后node不会退出?
更新



请注意,这不再适用。当使用once()时,Node.js将不会挂起,只要有活动的侦听器订阅了远程服务器,它就会保持打开。



原始



Firebase流程会打开服务器的套接字,并为这些连接上的传入数据建立侦听器。就像一个节点的Web服务器,等待传入的HTTP连接,这个过程就会保持这个过程打开。



要结束这个过程,你可以简单地使用process.exit()回调:

$ $ p $ $ $ $ c $ blahFirebase.once('value',function(snapshot){
//
process .exit();
});


Using node.js with the npm firebase.

var firebase = require('firebase');
var blahFirebase = new firebase('https://myfirebase.firebaseIO.com/blah');
blahFirebase.once('value', function (snapshot) {
    //
});

Why does node not exit when it is done reading the data?

解决方案

Update

Note that this is no longer applicable. Node.js will no longer hang when using once(), although it will be held open as long as there are active listeners subscribed to the remote server.

Original

The Firebase process opens sockets to the server and establishes listeners for incoming data on those connections. Just like a node web server, awaiting incoming HTTP connections, this holds the process open.

To end the process, you can simply utilize process.exit() from inside the callback:

blahFirebase.once('value', function (snapshot) {
    //
    process.exit();
});

这篇关于节点进程不会在firebase之后退出一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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