简体   繁体   English

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

[英]Azure Functions NodeJS Express app throws Unable to determine function entry point error

I am trying to create a simple hello world azure functions app using nodejs and express.我正在尝试使用 nodejs 和 express 创建一个简单的 hello world azure 函数应用程序。 But, i am getting the following error:但是,我收到以下错误:

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.

Here is my code:这是我的代码:

function.json函数.json

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

index.js:索引.js:

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

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

package.json:包.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"
  }
}

Then, i have a node_modules directory under the function app然后,我在函数应用程序下有一个node_modules目录

Any help is appreciated.任何帮助表示赞赏。 Thanks in advance!提前致谢!

The Azure Functions platform is rather opinionated because of its ability to do things like bindings and Triggers. Azure Functions 平台相当固执,因为它能够执行绑定和触发器等操作。 Functions coded in Node in Azure Functions need to be of the form.在 Azure Functions 中的 Node 中编码的函数需要采用以下形式。

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

You can find some JavaScript tips for Azure Functions here .可以在此处找到有关 Azure Functions 的一些JavaScript 提示 It looks like you are trying to do a simple HTTP-trigger function .看起来您正在尝试执行一个简单的HTTP 触发函数 Looking at your example, you would want something like this.看看你的例子,你会想要这样的东西。

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

Note that Azure Functions will be handling the routing of your HTTP requests, so you wouldn't likely want to use Express.js.请注意,Azure Functions 将处理您的 HTTP 请求的路由,因此您可能不想使用 Express.js。

Even if you want to use the Express with the Azure function you can go for this Azure AWS serverless Express即使您想将 Express 与 Azure 功能一起使用,您也可以选择此Azure AWS 无服务器 Express

package.包裹。 Its very useful.它非常有用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM