我正在尝试使用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/