Bessem
Bessem

Reputation: 55

initialise firebase in nodejs expressjs

i want to initialise a firebase (not firebase-admin) instance in Node.

import { initializeApp } from 'firebase/app';

const firebaseConfig = {
  //...
};

const app = initializeApp(firebaseConfig);

this won't work cause node works with commonjs exports and you can't require from firebase cause there is no exports..

Upvotes: 3

Views: 860

Answers (1)

Merhawi Fissehaye
Merhawi Fissehaye

Reputation: 2807

https://www.npmjs.com/package/firebase says:

This SDK is intended for end-user client access from environments such as the Web, mobile Web (e.g. React Native, Ionic), Node.js desktop (e.g. Electron), or IoT devices running Node.js. If you are instead interested in using a Node.js SDK which grants you admin access from a privileged environment (like a server), you should use the Firebase Admin Node.js SDK.

So use firebase-admin instead if you are planning to use firebase with the backend.

Install with npm install firebase-admin --save

To initialize define a variable export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json" and

const { initializeApp } = require('firebase-admin/app');
initializeApp()

Upvotes: 1

Related Questions