1

code:

    const admin = require('firebase-admin');

const serviceAccount = require("C:/Users/santo/Downloads/bestmpos-firebase-adminsdk.json");

admin.initializeApp({
 credential: admin.credential.cert(serviceAccount)
});

let fs = admin.firestore();
let auth = admin.auth();

start();
async function start (uid, userRecord){
  const info = await fs.collection('users').doc(uid).get();
 console.table(info.data());
 document.getElementById("greeting").innerHTML = "Bonjour";
}

Html code:

<script type="text/javascript" src="app3.js"></script>
    <body>
            <p id="greeting">Hello</p>
        </body>

when I wanted to pass bonjour value by using getElementById() there is a error saying that document.getElementById("greeting").innerHTML = "Bonjour"; ReferenceError: document is not defined

bheem
  • 11
  • 2
  • 1
    firebase-admin is meant to run on a node server, not the browser. Re check the documentation – Phix Feb 20 '22 at 21:01
  • 1
    This is usually caused by the code running before the page finishes rendering. Moving the script tag below the body should fix it – Pandicon Feb 20 '22 at 21:03
  • I just wanted to display the info from firebase to a HTML page – bheem Feb 20 '22 at 21:04
  • 1
    @Pandicon no, `document` *not existing* is usually caused by the code not running on a page at all but on Node.js – VLAZ Feb 20 '22 at 21:04
  • 1
    @Pandicon That would cause a different error (like not finding an element); `document` is available regardless of load status in a browser environment. – Dave Newton Feb 20 '22 at 21:05
  • https://stackoverflow.com/questions/32126003/node-js-document-is-not-defined – SuperStormer Feb 20 '22 at 21:08

0 Answers0