简体   繁体   English

无法在节点中运行新的firebase

[英]Can't run new firebase in node

I'm following along with this talk from google . 我正在跟随谷歌的这个谈话 However I can't instantiate a firebase object. 但是我无法实例化firebase对象。

I have a package.json file and started with: 我有一个package.json文件,并以:

npm install firebase --save

Then did the following: 然后做了以下事情:

let Firebase = require('firebase');
let myFire   = new Firebase('[link to my app]');

However, when I run the johhny-five app from terminal, I get the error: Firebase is not a function . 但是,当我从终端运行johhny-five app时,我收到错误: Firebase is not a function

How am I supposed to intstantiate the object? 我该如何实现对象? Did Firebase change their API? Firebase是否更改了API?

Note: I injected it into the repl and running >> typeof Firebase I get that it's actually an 'object'. 注意:我将它注入到repl并运行>> typeof Firebase我得到它实际上是一个'对象'。

Yes, they changed the API, take a look: Upgrade your Web / Node.js app from Firebase.com . 是的,他们更改了API,看看: 从Firebase.com升级您的Web / Node.js应用程序

This is how you do it now: 这是你现在的方式:

// See https://firebase.google.com/docs/web/setup#project_setup for how to
// auto-generate this config
var config = {
  apiKey: "apiKey",
  authDomain: "projectId.firebaseapp.com",
  databaseURL: "https://databaseName.firebaseio.com"
};

firebase.initializeApp(config);

var rootRef = firebase.database().ref();

To get the config values, go to the URL at the top of the previous code, Add Firebase to your Web Project , which guides you to do the following: 要获取config值,请转到上一代码顶部的URL, 将Firebase添加到Web项目 ,该URL指导您执行以下操作:

To add Firebase to your app, you'll need a Firebase project and a short snippet of code to add to your application HTML that has a few details about your project. 要将Firebase添加到您的应用中,您需要一个Firebase项目和一小段代码,以便添加到您的应用HTML中,其中包含有关项目的一些详细信息。

  1. Create a Firebase project in the Firebase console, if you don't already have one. 如果您还没有Firebase项目,请在Firebase控制台中创建Firebase项目。
    • If you already have an existing Google project associated with your app, click Import Google Project. 如果您已有与您的应用相关联的现有Google项目,请点击导入Google Project。 Otherwise, click Create New Project. 否则,单击“创建新项目”。
    • If you already have a project, click Add App from the project overview page. 如果您已有项目,请单击项目概述页面中的添加应用程序。
  2. Click Add Firebase to your web app. 点击添加Firebase到您的网络应用。
  3. Click Copy, then paste the code snippet into your application HTML. 单击“复制”,然后将代码段粘贴到应用程序HTML中。

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

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