Tomas Re Tomas Re - 2 months ago 9
Node.js Question

node process doesn't exit after firebase once

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?

Answer

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();
});