是否有可能确保iisnode尊重Azure中的NODE_PATH?

时间:2016-12-20 22:07:57

标签: node.js azure azure-web-app-service iisnode azure-app-service-envrmnt

希望能够进行非相对导入(例如配置等)并不罕见......

在自己运行节点可执行文件的世界中(开发环境,任何云提供程序......类似的东西),您只需设置一个env var并让节点运行时尊重它。

想象一下这样的项目结构: DIST | --foo     | --bar         | --baz             app.js | --config

在具有NODE_PATH = dist的app.js中的

,我可以简单地要求('config')并拥有我需要的东西。

在Azure App Services中,它似乎忽略了“应用程序设置”中的NODE_PATH。缺少什么或者这是不可能的?

1 个答案:

答案 0 :(得分:0)

在Azure App Services中,您可以使用以下步骤在Azure门户中设置NODE_PATH环境变量。

1,创建D:\home\site\my_node_modules\config目录并将index.js文件放在where中。在这种情况下,我只导出“名称”变量。

// D:\home\site\my_node_modules\config\index.js
var name = "foobar";
// export it
exports.name = name;

2,导航到Azure portal中的App Service,点击设置菜单中的应用设置,然后设置NODE_PATH变量如下:

enter image description here

3,在app.js文件中,您可以像require('config')一样:

var http = require('http')
var config = require('config')

http.createServer(function (req, res) {
    res.end(config.name)
}).listen(process.env.PORT || 3000)

4,最后,它运作良好。

enter image description here