unable to split Firebase functions in multiple files
See original GitHub issueI’m working with firebase functions and arrived to hundreds of functions, and now it is very hard to manage it in single index.js
file as shown in their lots of examples
I tried to split that functions in multiple files like:
--firebase.json
--functions
--node_modules
--index.js
--package.json
--app
--groupFunctions.js
--authFunctions.js
--storageFunctions.js
in this structure i devide my functions in three categories and put in that three files groupFunctions.js
authFunctions.js
storageFunctions.js
and tried to import that files in index.js
but i don’t know why it is not working for me
Here is groupFunctions.js
var functions = require('firebase-functions');
module.exports = function(){
exports.onGroupCreate = functions.database.ref('/groups/{groupId}')
.onWrite(event => {
console.log(`A group is created in database named:${event.params.groupId}.`);
// some logic...
//...
})
}
Here is index.js
file:
var functions = require('firebase-functions');
module.exports = require("./app/groupFunctions")();
my editor not giving any warning in this code but when i deploy this code with firebase deploy --only functions
it does not deploy function (if some functions already exist on firebase console, it remove all functions on deploy)
So I need help regarding this problem, looking forward to listen from you guise.
question is also asked on stackoverflow
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:35 (7 by maintainers)
Top GitHub Comments
Now you could even automate this a bit and register functions based on their file name. For instance with an index.js like this:
**UPDATE, this works:**
Where your file structure is like:
EDIT: Edited to reflect new name of environment variable.
I’ve created a slightly modified version of
index.js
that uses globbing to search for files ending with.function.js
. This allows me to organise my directory in any manner.EDIT: Edited to reflect new name of environment variable.