I am trying write Hello world kind of basic application with Firebase and Nodejs.
Application code
#cat app.js
var express = require('express');
var Firebase = require('firebase');
var app = express();
app.get('/',function(req,res) {
f();
res.send("success");
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
var onComplete = function(error) {
if (error) {
console.log('Synchronization failed');
} else {
console.log('Synchronization succeeded');
}
};
function f() {
var ref = new Firebase("https://dazzling-torch-XXXXX.firebaseio.com");
ref.set({
location: {
city: "San Francisco",
state: "California",
zip: 94103
}
},onComplete);
ref.child("location/zip").on("value", function(snapshot) {
console.log(snapshot.val()); // Alerts "San Francisco"
});
}
Library versions -
npm --version && node --version && firebase --version
1.3.6
v0.10.42
2.2.1
Node command -
- node app.js
- open browser http://localhost:3000/
Debugger Output
p:0: Making a connection attempt
c:0:17: Connection created
c:0:17:0 Websocket connecting to wss://dazzling-torch-XXXX.firebaseio.com/.ws?v=5
c:0:17:0 WebSocket error. Closing connection.
c:0:17:0 Network error: wss://dazzling-torch-XXXX.firebaseio.com/.ws?v=5: getaddrinfo ESRCH
c:0:17:0 WebSocket is closing itself
c:0:17:0 Websocket connection was disconnected.
c:0:17: Realtime connection failed.
c:0:17: Closing realtime connection.
c:0:17: Shutting down all connections
p:0: data client disconnected
p:0: Trying to reconnect in 17797.816018858393ms
but it is not updating firebase data. I am using default security rules.
Thanks Pari
ref.set()takes an optional second callback function that will be called in case of any errors (see the docs for info). Setting that and logging the errors might show a hint as to what is happening.