aaz*_*eem 0 azure node.js 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.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
函数.json
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"entryPoint": "index",
"disabled": false
}
Run Code Online (Sandbox Code Playgroud)
索引.js:
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Express JS Hello World App!!!'))
Run Code Online (Sandbox Code Playgroud)
包.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"
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我node_modules在函数app下有一个目录
任何帮助表示赞赏。提前致谢!
Azure Functions 平台相当固执,因为它能够执行绑定和触发器等操作。在 Azure Functions 的 Node 中编码的函数需要采用以下形式。
module.exports = function(context) {
// function logic goes here :)
};
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到一些有关 Azure Functions 的 JavaScript 技巧。看起来您正在尝试执行一个简单的HTTP 触发函数。看看你的例子,你会想要这样的东西。
module.exports = function(context, req) {
context.res = {
// status defaults to 200 */
body: "Express JS Hello World App!!!"
};
context.done();
};
Run Code Online (Sandbox Code Playgroud)
请注意,Azure Functions 将处理 HTTP 请求的路由,因此您可能不想使用 Express.js。
| 归档时间: |
|
| 查看次数: |
1950 次 |
| 最近记录: |