Javascript Firebase函数-用于组织函数的多个js文件
我有一个名为Javascript Firebase函数-用于组织函数的多个js文件,javascript,node.js,firebase,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Functions,我有一个名为functions的文件夹,里面有index.js。 在index.js上,我有一个接受所有http的主函数: exports.contentServer = functions.https.onRequest((request, response) => { 因为我有更多的函数,我需要组织我的文件,我想添加另一个文件,比如payments.js,这样index.js就可以调用payments.js中的函数,甚至一旦创建就会从payment.js中触发回调 如果我只是在fu
functions
的文件夹,里面有index.js
。
在index.js
上,我有一个接受所有http的主函数:
exports.contentServer = functions.https.onRequest((request, response) => {
因为我有更多的函数,我需要组织我的文件,我想添加另一个文件,比如payments.js
,这样index.js
就可以调用payments.js
中的函数,甚至一旦创建就会从payment.js
中触发回调
如果我只是在functions
中创建另一个js
文件,它将无法工作
要在另一个新的js
文件中使用单个云函数,必须做些什么?您可以使用标准的nodejsrequire
在其他文件中加载代码
index.js
const otherFunctions = require('./other.js');
exports.contentServer = functions.https.onRequest((request, response) => {
otherFunctions.other()
}
exports.other = function() { ... }
other.js
const otherFunctions = require('./other.js');
exports.contentServer = functions.https.onRequest((request, response) => {
otherFunctions.other()
}
exports.other = function() { ... }
我建议阅读以了解更多信息。那么如何在其他函数中调用firestore?通常,它需要在index.js中进行管理员初始化