Firebase with Node, "browser-targeted Firebase bundle"

Viewed 2400

I got the npm "firebase" package for Node, made a firebaseConfig.js file and then added this:

const firebase = require("firebase/app");
console.log(firebase);

const firebaseConfig = {
 ...
};

firebase.initializeApp(firebaseConfig);

At first, I got an error saying "initializeApp isn't a function", which I really didn't get, after seeing the contents of firebase, I changed the last line to

firebase.default.initializeApp(firebaseConfig);

Which works, but now I'm getting this warning on the console;

      Warning: This is a browser-targeted Firebase bundle but it appears it is being
      run in a Node environment.  If running in a Node environment, make sure you
      are using the bundle specified by the "main" field in package.json.

I really don't get what I should do here, I could really use some guidance so thanks a lot in advance!

1 Answers

When you use firebase in server-side, you should use firebase-admin.

To set up administrative access from privileged environments (such as servers) set up the Firebase Admin SDK instead.

https://firebase.google.com/docs/admin/setup

Related