I am ready to deploy my nodejs backend to firebase, and followed the basic instructions to try and get things running. Before initializing firebase functions in my app, my file structure was a basic node app:
|- /routes
|- /models
...
|- app.js <-- where express "app" is initialized and my routes are brought in
|- package.json
I ran firebase init functions in my project's root directory, which made a functions folder at the same level as my routes, models, and other "source" folders.
|- /routes
...
|- /functions
|- index.js
|- package.json
...
|- app.js
|- package.json
I've been able to cd into the new functions folder and run npm run serve to test that the endpoint is working locally. I can successfully make requests through postman this way.
Problem is that when trying to deploy via npm run deploy (in functions dir), it throws an error seemingly related to the entry file for firebase:
2022-09-11T18:32:03.676588Z ? app: Provided module can't be loaded.
2022-09-11T18:32:03.676627Z ? app: Did you list all required modules in the package.json dependencies?
2022-09-11T18:32:03.676656Z ? app: Detailed stack trace: Error: Cannot find module '../app'
my functions/package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
...
"main": "../app.js",
...
}
app.js:
...
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const app = express();
...
admin.initializeApp(functions.config().firebase);
exports.app = functions.https.onRequest(app);
I also tried first to export app from app.js and require it in functions/index.js, before using the same two lines to initialize firebase in functions/index.js. It threw a similar error, saying it couldn't find '../app'.
It seems like I may just need to change my projects structure a bit? Is it necessary for the firebase files to live in a functions folder at all? Do I need a separate package.json for that or can it all be in one at the root?