Node.js Google云功能:使用单个存储库实现多个功能

Node.js Google云功能:使用单个存储库实现多个功能,node.js,google-cloud-platform,google-cloud-functions,Node.js,Google Cloud Platform,Google Cloud Functions,我一直在试图弄清楚如何保存一个存储库并将其用于多个云功能,这让我很恼火。我不想有多个“项目”,每个项目都有自己的index.js。另外,从index.js自动导出每一个可能的函数根本没有效率。我想要一种只动态导出该调用所需函数的方法。幸运的是,每次调用项目时,它所寻找的函数都会在process.env.function\u NAME中提供,因此您可以对其进行评估并在运行时导出它 function init(event, callback) { var fn = require('./my-e

我一直在试图弄清楚如何保存一个存储库并将其用于多个云功能,这让我很恼火。我不想有多个“项目”,每个项目都有自己的
index.js
。另外,从
index.js
自动导出每一个可能的函数根本没有效率。我想要一种只动态导出该调用所需函数的方法。

幸运的是,每次调用项目时,它所寻找的函数都会在
process.env.function\u NAME
中提供,因此您可以对其进行评估并在运行时导出它

function init(event, callback) {
  var fn = require('./my-event.js'); // Exports just a single function that takes the `callback`.

  fn(callback);
};
exports[process.env.FUNCTION_NAME] = init;

幸运的是,每次调用项目时,
process.env.function\u NAME
中都会提供它要查找的函数,因此您可以计算该函数并在运行时导出它

function init(event, callback) {
  var fn = require('./my-event.js'); // Exports just a single function that takes the `callback`.

  fn(callback);
};
exports[process.env.FUNCTION_NAME] = init;

目前还不清楚这有什么帮助。如果我有一个具有以下结构的repo:src/functions/myfunca src/functions/myfuncb src/lib/functions-package.json节点_模块之间共享的任何内容我如何部署myfunca?gcloud functions deploy--source=src/functions/myfunca将只查看myfunca中的内容。不清楚这有什么帮助。如果我有一个具有以下结构的repo:src/functions/myfunca src/functions/myfuncb src/lib/functions-package.json节点_模块之间共享的任何内容我如何部署myfunca?gcloud functions deploy--source=src/functions/myfunca将只查看myfunca中的内容。