node.js - Azure Functions NodeJS Express 应用程序抛出无法确定函数入口点错误

标签 node.js azure express azure-functions azure-functions-runtime

我正在尝试使用nodejs和express创建一个简单的hello world azure函数应用程序。但是,我收到以下错误:

Exception while executing function: Functions.httpexpressapp. mscorlib: Unable to determine function entry point. If multiple functions are exported, you must indicate the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.

这是我的代码:

函数.json

 {
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "entryPoint": "index",
  "disabled": false
}

index.js:

const express = require('express')
const app = express()

app.get('/', (req, res) => res.send('Express JS Hello World App!!!'))

package.json:

{
  "name": "httpexpressapp",
  "version": "1.0.0",
  "description": "sample app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "john doe",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3"
  }
}

然后,我在函数应用程序下有一个 node_modules 目录

感谢任何帮助。提前致谢!

最佳答案

Azure Functions 平台相当固执,因为它能够执行绑定(bind)和触发器等操作。在 Azure Functions 的 Node 中编码的函数需要采用以下形式。

module.exports = function(context) {
    // function logic goes here :)
};

你可以找到一些JavaScript tips for Azure Functions here 。看起来您正在尝试做一个简单的 HTTP-trigger function 。看看你的例子,你会想要这样的东西。

module.exports = function(context, req) {
    context.res = {
        // status defaults to 200 */
        body: "Express JS Hello World App!!!"
    };
    context.done();
};

请注意,Azure Functions 将处理 HTTP 请求的路由,因此您可能不想使用 Express.js。

关于node.js - Azure Functions NodeJS Express 应用程序抛出无法确定函数入口点错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51162930/

相关文章:

node.js - Nest.js 优雅关闭

node.js - 如何从 firebase auth 正确获取 Twitter screenName?

azure - 如何将包含 terraform 文件的文件夹放入 docker 容器中并进一步将其部署到 azure

express - 使用流输出pdf

javascript - Multer上传文件+JSON对象

node.js - 在 sequelize seeds 中查找记录

javascript - 如何在我的电子邮件、nodemailer 和 Handlebars 中添加图像?

python - 在 Azure Python SDK 中创建自动化帐户的错误请求

Azure 数据湖 VS Azure HDInsight

node.js - 如何在node js中使用express重定向后app.get