1

I am working on refactoring some code from node flex environment to Cloud Functions for Firebase. Is there a best practice for having many files worth? Is the best route just using firebase init functions a bunch of times and associating the same project?

That seems like it would make having them all in a single repository messy and difficult. How can I have many files worth of Cloud Functions for Firebase in an organized and maintainable manor?

Thanks in advance.

AL.
  • 36,815
  • 10
  • 142
  • 281
Carl Lippert
  • 329
  • 3
  • 9
  • 1
    I normally put most of my code into separate files, that export a module. I then import that module into my index.js, where I tie it to its trigger. For an example see: http://stackoverflow.com/questions/42726310/how-to-test-firebase-functions-locally-on-pc/42729988#42729988 – Frank van Puffelen Mar 20 '17 at 03:46
  • "best practices" is a matter of opinion, but you should look into using JavaScript's require() to modularize your code as needed. – Doug Stevenson Mar 20 '17 at 05:01
  • index.js can still get prohibitively large and messy eventually with this implementation. Am I right? example: Say I have 50 functions and they all have their own triggers that would be more than I would like to have in a file. I will definitely be using @frankvanpuffelen's example for the time being. – Carl Lippert Mar 21 '17 at 04:23

0 Answers0