Organize Cloud Functions for Firebase

后端 未结 4 555
小鲜肉
小鲜肉 2020-12-17 09:15

What is the best practice to organize all our Cloud Functions for Firebase?

I see from the sample GitHub repository that all functions reside in a single index

4条回答
  •  执笔经年
    2020-12-17 09:54

    You could use something like export { functionName } from './file' at your index.js file.

    /functions/index.js
    // This is the main entry point for the app written in ES that is compatible with node lts
    import * as functions from 'firebase-functions';
    
    export { sendWelcomeEmail } from './userEmails';
    
    exports.helloWorld = functions.https.onRequest((request, response) => {
      let helloMsg = `Hello!`;
      response.send(helloMsg);
    });
    

提交回复
热议问题