关于node.js:是否可以确保iisnode在Azure中遵守NODE_PATH?

Is it possible to ensure iisnode respects NODE_PATH in Azure?

希望具有非相对导入(例如,用于配置等)的情况并不少见。

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

想象一下这样的项目结构:
dist
| --foo
|-酒吧
|-巴兹
app.js
| --config

在具有NODE_PATH = dist的app.js中,我可以简单地需要('config')并拥有我所需要的。

在Azure App Services中,它似乎忽略了"应用程序设置"中的NODE_PATH。是否缺少某些东西或这是不可能的?


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

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

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

2,在Azure门户中导航到您的App Service,在"设置"菜单中单击"应用程序设置",然后如下所示设置NODE_PATH变量:

enter

1
2
3
4
5
6
var http = require('http')
var config = require('config')

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

4,终于可以了。

enter