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?
Try using: firebaseRef. off(); This will end your connection with firebase and stop communicating with the database.
Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.
Overview. Firebase provides the tools and infrastructure you need to develop, grow, and earn money from your app. This package supports web (browser), mobile-web, and server (Node. js) clients.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With