gpt4 book ai didi

javascript - 无法在 Node 中运行新的 firebase

转载 作者:搜寻专家 更新时间:2023-10-31 23:08:09 26 4
gpt4 key购买 nike

我正在关注 this talk from google .但是我无法实例化 firebase 对象。

我有一个 package.json 文件并开始于:

npm install firebase --save

然后做了以下事情:

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

但是,当我从终端运行 johhny-five 应用程序时,出现错误:Firebase 不是函数

我应该如何实例化对象? Firebase 是否更改了他们的 API?

注意:我将它注入(inject) repl 并运行 >> typeof Firebase 我知道它实际上是一个“对象”。

最佳答案

是的,他们更改了 API,看一下:Upgrade your Web / Node.js app from Firebase.com .

这就是你现在的做法:

// 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();

要获取 config 值,请转至前面代码顶部的 URL,Add Firebase to your Web Project ,它会指导您执行以下操作:

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.

  1. Create a Firebase project in the Firebase console, if you don't already have one.
    • If you already have an existing Google project associated with your app, click Import 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.
  3. Click Copy, then paste the code snippet into your application HTML.

关于javascript - 无法在 Node 中运行新的 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37310808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com