0

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 -

  1. node app.js
  2. 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

5
  • Any error message? What do you get when you make a request to / route? Commented Apr 9, 2016 at 15:38
  • 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. Commented Apr 9, 2016 at 15:42
  • Thanks for reply. I have added debugger . Debug output - c:0:2: Connection created c:0:2:0 Websocket connecting to wss://dazzling-torch-1380.firebaseio.com/.ws?v=5 c:0:2:0 WebSocket error. Closing connection. c:0:2:0 Network error: wss://dazzling-torch-1380.firebaseio.com/.ws?v=5: getaddrinfo ESRCH c:0:2:0 WebSocket is closing itself c:0:2:0 Websocket connection was disconnected. c:0:2: Realtime connection failed. c:0:2: Closing realtime connection. c:0:2: Shutting down all connections p:0: data client disconnected Commented Apr 9, 2016 at 16:09
  • Added onComplete callback function for set and debugger output in main post. Thanks Commented Apr 9, 2016 at 16:19
  • Not really an answer, but the output of my steps is below. Commented Apr 10, 2016 at 15:24

1 Answer 1

1

I just ran on node v0.10.37 and firebase 2.4.2 (those are really the only versions that should matter) and it connected and wrote the data instantly.

node app.js
Example app listening on port 3000!
p:0: Browser went online.
0: set {"path":"/36518762","value":{"location":{"city":"San Francisco","state":"California","zip":94103}},"qh":null}
p:0: Buffering put: /36518762
p:0: Listen called for /36518762/location/zip default
event: /36518762/location/zip:value:94103
94103
p:0: Making a connection attempt
c:0:0: Connection created
c:0:0:0 Websocket connecting to wss://stackoverflow.firebaseio.com/.ws?v=5
c:0:0:0 Websocket connected.
c:0:0: Reset packet received.  New host: s-usc1c-nss-158.firebaseio.com
c:0:0: Shutting down all connections
c:0:0:0 WebSocket is being closed
c:0:0:0 Websocket connection was disconnected.
c:0:0:1 Websocket connecting to wss://s-usc1c-nss-158.firebaseio.com/.ws?v=5&ns=stackoverflow
c:0:0:1 Websocket connected.
c:0:0: Realtime connection established.
p:0: connection ready
p:0: reportStats {"c":{"sdk.js.2-4-2":1}}
p:0: {"r":1,"a":"s","b":{"c":{"sdk.js.2-4-2":1}}}
p:0: Listen on /36518762/location/zip for default
p:0: {"r":2,"a":"q","b":{"p":"/36518762/location/zip","h":""}}
p:0: {"r":3,"a":"p","b":{"p":"/36518762","d":{"location":{"city":"San Francisco","state":"California","zip":94103}}}}
p:0: from server: {"r":1,"b":{"s":"ok","d":""}}
c:0:0: Primary connection is healthy.
p:0: handleServerMessage d {"p":"36518762/location/zip","d":94103}
p:0: from server: {"r":2,"b":{"s":"ok","d":{}}}
p:0: listen response {"s":"ok","d":{}}
p:0: from server: {"r":3,"b":{"s":"ok","d":""}}
p:0: p response {"s":"ok","d":""}
Synchronization succeeded

It looks like your web socket is getting rejected way before that. You might want to check for proxies in between your client and the Firebase server. Try on a different network, that sort of thing.

  • Try the diagnostic page
  • ping INSTANCE.firebaseio.com
  • tracert INSTANCE.firebaseio.com
  • Run this curl command, substituting your Firebase URL at the end (don't forget .json!).
  • Try a different computer on a different network

Note that these are all just steps to help you troubleshoot connection problems.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Frank, your steps did help. It was problem with my internet provider. I have launched AWS instance with node.js installed. My program is working without any error on aws instance.
I tried to upvote your answer but as I don't have enough points, I could not do it. :(.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.