Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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..

like image 376
Bessem Avatar asked May 07 '26 16:05

Bessem


1 Answers

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()
like image 138
Merhawi Fissehaye Avatar answered May 10 '26 07:05

Merhawi Fissehaye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!