Can't we Write multiple files in Firebase Cloud Functions

Viewed 3851

How can we implement Micro-service architecture using Firebase Cloud Functions can we write multiple .js files unlike writing all functions into index.js so that we need not re-deploy all functions for change in single function

3 Answers

Hi you can do this in the following way.

alpha.js

const functions = require('firebase-functions');
exports.alphaFunction = functions.https.onRequest((request, response) => {
   // Your code
});

index.js

const functions = require('firebase-functions');
var alphaFunction = require('./alpha');
exports.mainFunction = functions.https.onRequest((request, response) => {
    //Inside your main function
    exports.alphaFunction = alphaFunction.alphaFunction();
});
Related