简体   繁体   中英

Can't run new firebase in node

I'm following along with this talk from google . However I can't instantiate a firebase object.

I have a package.json file and started with:

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 .

How am I supposed to intstantiate the object? Did Firebase change their API?

Note: I injected it into the repl and running >> typeof Firebase I get that it's actually an 'object'.

Yes, they changed the API, take a look: Upgrade your Web / Node.js app from Firebase.com .

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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