My Cloud Functions for Firebase index.js is getting to the size where I'd like to start splitting the code file off into multiple module files.
However it's unclear whether I need to call this line at the top of each module/file which will be accessing the Firebase database.
admin.initializeApp(functions.config().firebase);
Please excuse me if this is really obvious. I am not an experienced Node.js user.
For all of the code in all of your modules that want to make use of the Firebase Admin SDK, you will need to have an initialized admin
object available. And in order to initialize the Admin SDK, you will need a functions
object that comes from the following line:
const functions = require('firebase-functions');
So, you could do this at the top of all your module files:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
And that would provide an initialized admin object for you to use in the functions defined in that file. You can call the objects whatever names you want.
Alternately, you could figure out another way to get a single admin object into your code, but you have no obligation to do so. It's completely up to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With