Should I have two package.jsons for a node.js website using Firebase?


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:

└─package.json <- contains firebase-admin and firebase-functions dependencies
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.

Answered By – Constantin Beer

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published