Firebase使用Nodejs API插入数据

时间:2016-04-09 15:19:55

标签: node.js firebase

我正在尝试使用Firebase和Nodejs编写Hello world类基本应用程序。

申请代码

#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"
});
}

图书馆版本 -

npm --version && node --version && firebase --version
1.3.6
v0.10.42
2.2.1

节点命令 -

  1. node app.js
  2. 打开浏览器http://localhost:3000/
  3. 调试器输出

    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  
    

    但它没有更新firebase数据。我正在使用默认安全规则。

    由于 彩

0 个答案:

没有答案