in my app.js that is located in the root folder, I mean Mywebsite/app.js
i can access require variable
const express = require("express");
const admin = require("firebase-admin");
but in all other folders like public
or static
or views
folders, I can not use require and also I can't import any library like this one
import admin from "firebase-admin"
and im getting this error for import
SyntaxError: Unexpected identifier 'admin'. import call expects exactly one argument.
or this for require
ReferenceError: Can't find variable: require
I'm new to web development especially when it comes to using an express app now all my problem is with require or importing a library in javascript files, is there any other ways to include or call models in nodejs rather than require
here is my dependencies
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"csurf": "^1.11.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"firebase": "^8.6.3",
"firebase-admin": "^9.9.0",
"firebase-functions": "^3.14.1",
"nodemon": "^2.0.7",
"popups": "^1.1.3",
"requirejs": "^2.3.6"
},
have you tried using
const { admin } = require("firebase-admin");
?