javascript - Firebase 函数 - 多个 js 文件来组织函数
问题描述
我有一个名为 的文件夹functions
,里面有index.js
. 在index.js
我有接受所有 http 的主要功能:
exports.contentServer = functions.https.onRequest((request, response) => {
由于我有更多的功能,我需要组织我的文件,并且我想添加另一个文件,比如说payments.js
,以便index.js
可以调用里面的函数 payments.js
,或者甚至onCreate
会从payment.js
.
如果我只是在 中创建另一个js
文件functions
,它将无法正常工作。
必须做什么才能在另一个新 js
文件中拥有一个云功能?
解决方案
您可以使用标准 nodejsrequire
在其他文件中加载代码。
index.js
const otherFunctions = require('./other.js');
exports.contentServer = functions.https.onRequest((request, response) => {
otherFunctions.other()
}
其他.js
exports.other = function() { ... }
我建议阅读文档以获取更多信息。
推荐阅读
- angular - Angular 应用程序的子组件中没有 NgControl 提供程序
- linux - VSCode 在 Linux 中使用哪个字体文件夹?
- python - Twisted - 将结果传递给多个回调
- python - 使用SQL查询作为数据源摆脱python中的多个html标签
- javascript - Discord.js 让你的机器人等待回复
- vmware-clarity - Clarity Datagrid & Promise / 主题绑定栏
- php - 尝试从命名空间“App\DataFixtures”加载类“BaseFixture”。您是否忘记了另一个名称空间的“使用”语句?
- tensorflow - 如何使用 Tensorflow 2.0 获得可重现的结果?
- python - 将 groupedby pandas 数据框(多个但不是所有列)从长转换为宽
- java - 如何在freemarker中获取列表大小?