google-cloud-functions - 如何在 Node 6 上构建模拟器但 Node 6 不推荐使用 Functions 时在本地运行 Google Cloud Functions?
问题描述
Google Cloud Functions 模拟器仅在节点 6 上受支持: https ://github.com/GoogleCloudPlatform/cloud-functions-emulator
注意:模拟器仅支持 Node v6.xx,不支持 Node v8.xx 或 Python。”
但是,节点 6 不推荐使用 Google Cloud Functions: https ://cloud.google.com/functions/docs/concepts/nodejs-6-runtime
Node.js 6 运行时已被弃用。为确保您的函数在受支持的 Node.js 版本上,请将它们迁移到 Node.js 8 或 Node.js 10。2020-04-22 之后,使用 Node.js 6 的函数部署将被阻止。在此时间之后继续使用 Node.js 6 的 Cloud Functions 可能会被禁用。”
如何在本地运行函数(为 Node 8 编写)?
解决方案
谷歌(2019 年 4 月)刚刚发布了一个新的 Cloud Functions 测试和开发框架,用于基于 Node.js 的逻辑。这个框架的名字叫做Functions Framework for Node.js并且在 Github 上开源。如果您访问刚刚提供的链接,您将找到有关如何下载和使用它的详细文档。在最高(和摘要)级别:
npm install @google-cloud/functions-framework
编写你的代码。
exports.helloWorld = (req, res) => {
res.send('Hello, World');
};
- 使用运行您的代码
npx @google-cloud/functions-framework --target=helloWorld
虽然这些是备忘单说明,但我强烈建议您阅读 Github 存储库中的整个 README 文档。
推荐阅读
- android - 编辑 ImageView 布局以围绕可绘制对象
- interface - Haxe:与接口匹配的函数参数
- kubernetes - 扩展 GKE K8s 集群中断网络
- mongodb - 如何在没有连接的情况下基于另一个集合更新集合?
- angular - 为什么我的 ngFor 不工作。我对角度很新,请耐心等待
- excel - VBA在公式中使用变量值作为单元格引用
- php - Laravel {{ auth()->user()->plan['name'] }} 如果为空
- vba - 使用 excel VBA 将 Powerpoint 保存为 PDF
- r - 我们如何选择包含 R 中某一列中信息的 csv 文件行?
- android - 在最近的 Playstore 控制台中修改隐私政策 URL