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
文件中使用单个云函数,必须做些什么?

您可以使用标准的nodejs
require
在其他文件中加载代码

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中进行管理员初始化