如何在NodeJS Azure Functions中使用包管理? [英] How can i use package management in NodeJS Azure Functions?
问题描述
我正在尝试将此示例项目构建为Azure函数,并且它需要一些软件包 https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-App-only
I'm trying to build this sample project as a Azure Function and it requires some packages https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-App-only
我看到我可以使用 https://azure.microsoft.com/zh-CN/documentation/articles/functions-reference/#nodejavascript-api
我试图用这个
var request = require('request');
此声明
You can include packages in your function directory (i.e. via npm install) and then import them to your function in the usual ways (i.e. via require('packagename'))
因此,我像C#Azure函数使用的那样在其中创建了一个project.json:
So I created a project.json with this in it like the C# Azure Function uses:
{
"frameworks": {
"net46":{
"dependencies": {
"chalk": "^1.1.1",
"q": "^1.4.1",
"request": "^2.67.0"
}
}
}
}
并得到此错误
2016-04-06T19:49:42.026 Exception while executing function: Functions.MicrosoftGraphWebHookNode. mscorlib: One or more errors occurred. Error: Cannot find module 'request'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (D:\home\site\wwwroot\MicrosoftGraphWebHookNode\index.js:1:77)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17).
project.json是否可以工作?
Should the project.json work?
推荐答案
您可以将package.json
包含在函数目录中,并使用Kudu或Azure中的控制台像通常使用Node.js projets一样运行npm install
门户.
You can include your package.json
in you function directory and run npm install
as you normally would with Node.js projets using Kudu or the Console in the Azure portal.
更多信息可以在这里找到: https://azure.microsoft.com/en -us/documentation/articles/functions-reference/#node-version-amp-package-management
More information can be found here: https://azure.microsoft.com/en-us/documentation/articles/functions-reference/#node-version-amp-package-management
这篇关于如何在NodeJS Azure Functions中使用包管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!