I'm building a simple website using Node.js and Express.js with a typical root-level package.json
to handle my dependencies.
Now, I'm learning to use Google Firebase for web hosting and functions to deploy the website. Upon executing the Firebase CLI command firebase init functions
, I now have a functions
directory that also has a package.json
file. I transferred my initial /app.js
file into the functions/index.js
and it's working fine when I firebase serve
for testing.
Here is my project directory structure:
functions
└─views
└─index.js
└─package.json <- contains firebase-admin and firebase-functions dependencies
public
└─images
├─styles
└─scripts
firebase.json
package.json <- contains express, handlebars, etc. dependencies I had originally created.
Is it good practice to now have 2 package.json
files for this project? One for Firebase functions, and the other for my app? Should I consolidate them into one, and if so, which one?
I'm still new to back end development, so any advice would be deeply appreciated!
You have to see your functions
as your backend server. In the end if you host your web app and call your functions
via http requests your functions
act as independent "components" even then they are in the same place in your local project. That's why they need their own package.json
.