简体   繁体   English

Firebase不适用于NodeJS

[英]Firebase does not work with NodeJS

Following Firebase's tutorial, I was able to start posting data immediately from the frontend, using the cdn: 遵循Firebase的教程,我能够立即使用cdn从前端开始发布数据:

<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>

and: 和:

      var myDataRef = new firebase('https://intense-torch-1234.firebaseio.com/');

      $('#messageInput').keypress(function (e) {
        if (e.keyCode == 13) {
          var name = $('#nameInput').val();
          var text = $('#messageInput').val();
          myDataRef.push({name: name, text: text});
          $('#messageInput').val('');
        }
      });

      myDataRef.on('child_added', function(snapshot) {
        var message = snapshot.val();
        console.log('TESTING', snapshot);
      });

This shows up at my Firebase app location. 这显示在我的Firebase应用程序位置。

I need to use this for NodeJS, so I installed the NPM Firebase module . 我需要将其用于NodeJS,因此我安装了NPM Firebase模块

I am doing pretty much the same thing here... 我在这里做着差不多的事情...

var firebase = require('firebase');

exports.handler = function (event, context, callback) {

    var myDataRef = new firebase('https://intense-torch-1234.firebaseio.com/');

    myDataRef.push({name: 'myname', text: 'sometext'});

    myDataRef.on('child_added', function(snapshot) {
        var message = snapshot.val();
        console.log('TESTING', snapshot.val());
    });

The console log fires after my request comes in (from Slack) and shows that the data is coming in. However, it is not updating in my Firebase database. 我的请求(从Slack)传入后,控制台日志将触发,并显示数据正在传入。但是,Firebase数据库中没有更新该日志。

Are there other configurations I need to do for Node NPM firebase? 我需要为Node NPM firebase做其他配置吗?

As for other configurations, you need to import the package by using require as per the instructions. 对于其他配置,您需要按照说明使用require导入软件包。

var Firebase = require('firebase');
var myRootRef = new Firebase('https://myprojectname.firebaseIO.com/');
myRootRef.set("hello world!");

There also should be error messages from node for not doing this. 还应该有来自节点的错误消息,提示您不这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM