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?


In the new Firebase API you should use firebase.app.App.delete() to free the resources its holding. For example:

var app = firebase.initializeApp({ ... });
var db = firebase.database();

// Do something

app.delete(); // Release resources

Do not use process.exit() since it will stop the entire process (which is not what you would usually want).


My case is using firebase admin,

const  admin = require('firebase-admin');

and I can end node process by

return admin.app().delete();

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