简体   繁体   English

如何将我的 nodejs 库包含在 Google Cloud Functions 中

[英]How to include my nodejs libraries with Google Cloud Functions

I've just made my first decent Google Cloud Function and now I'd like to refactor it into libraries.我刚刚制作了我的第一个像样的 Google Cloud Function,现在我想将它重构到库中。

Example, I've got my Cloud Function and I'd like to require a library I've created, not something installed from NPM.例如,我有我的 Cloud Function,我想要一个我创建的库,而不是从 NPM 安装的库。

How do I deploy these libraries to Google Cloud Functions?如何将这些库部署到 Google Cloud Functions?

If I understand your question correctly, you want to create a module out of your common.js file.如果我正确理解你的问题,你想从你的common.js文件中创建一个模块。

If that is the case, in common.js , export it like so:如果是这样,在common.js中,像这样导出它:

export default function(){
  // Here is your common code
}

and then just import it into your function file:然后将其导入到您的函数文件中:

import common from './common.js';

Try using --include-node-modules flag to include node_modules folder with deployed sources.尝试使用 --include --include-node-modules标志来包含带有已部署源的node_modules文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在 Python 中使用我的谷歌云 API 密钥在云功能中 - How to i user my google cloud API key in cloud functions in Python 如何调试 Google Cloud Functions 中的 Axios 错误? - How to debug Axios Errors in Google Cloud Functions? 如何使用 Cloud Functions 读取存储在 Google Cloud Storage 中的 CSV 数据 - How to read CSV data stored in Google Cloud Storage with Cloud Functions Cloud Firestore、nodejs(云函数)、同步访问 - Cloud Firestore , nodejs (cloud functions), synchronize access 我位于亚洲的 Google Cloud 功能的美国 IP 地址 - US IP address to my Google Cloud functions located in Asia Google Cloud Storage + Nodejs:如何删除文件夹及其所有内容 - Google Cloud Storage + Nodejs: How to delete a folder and all its content 在哪里可以找到 nodejs google pubsub 库的常量? - Where to find constants for nodejs google pubsub libraries? 谷歌云功能 Firebase 使用 NodeJS 更新 FieldValue.increment(1) - TypeError: FieldValue.increment is not a function - Google cloud functions Firebase Update FieldValue.increment(1) using NodeJS - TypeError: FieldValue.increment is not a function Google Cloud - 错误报告客户端库 - Google Cloud - Error Reporting Client Libraries Google Cloud Functions 如何检测活动实例的数量? - Google Cloud Functions how to detect number of active instances?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM