I know this was already asked here, BUT it does not answer my question. My question is how can we break apart index.js for Cloud Functions including the onWrite calls and such.
I realize you can use "require" and bring in outside code. It still leaves a bit of code ( in Franks OCR example, for example) , in index.js.
Ideally I'd love to be able to move an entire onWrite event trigger to another file.
EXAMPLE in index.js:
exports.sysQueueUserNew = functions.database.ref("/sys/queue/user_new/{queueId}").onWrite((event) => {
// do something
})
How can I move the entire function event watch/call to another js file, and call it from index.js?
My index.js has grown quite large, and reading it for organizational purposes has become a PAIN.
Ideally I'd like my index.js to be very organized such as:
--in index.js --
/// User cleanup
userHelpers()
/// SYS Logs
sysLogs()
--and in userHelpers.js have the onWrite trigger for example---
functions.database.ref("/sys/queue/user_new/{queueId}").onWrite((event) => {
// create user
})
etc....
Is this possible without having to have code written like so (a' la Franks OCR example):
var test = require('./test')
exports.sysQueueUserNew = functions.database.ref("/sys/queue/user_new/{queueId}").onWrite((event) => {
// do something
test.doCleanup()
})
Thanks in advance....