Hi there,
How can I split my functions in its own files. I have tried to use require command, but it seems that I can't reimport resources like firebase-admin.
I am planning to write a lot of functions and put them all in index.js does not sound good.
Thanks in advance
I'm importing other .js files with firebase functions. Just think of the functions folder as root, I was mistakenly trying to import files from /functions parent folder.
index.js
var paymentFunctions = require('./payment_functions');
along with something like:
exports.paymentMethodTask = functions.database.ref('/newPaymentMethodTask/{taskId}').onWrite(event => {
return paymentFunctions.processPaymentMethodTask(event);
});
With the folder structure:
/myProject/functions/index.js
/myProject/functions/payment_functions.js
Then export your functions in payment_functions.js as normal:
module.exports = {
processPaymentMethodTask: function test(event) {
//do something here with the event
}
};
@ahaverty I changed my code as you suggested and it worked like a charm!
Thank you very much!
Most helpful comment
along with something like:
With the folder structure:
Then export your functions in payment_functions.js as normal: