[英]How to read .env file variables in Nodejs within Azure function
我有以下代码在本地运行良好,但是当我部署到 Azure function 时,它无法在运行时读取 .env 文件的内容,当调试每个配置项时“未定义”。 .Env 文件以正确的条目部署到 Azure 并且当我硬编码配置变量以进行测试时,function 正确执行。 我想我需要做一些不同的事情才能让它在 Azure 上工作?
const sql = require('mssql')
require('dotenv').config();
const dbConfig = {
server: process.env.databaseServer,
database: process.env.databaseName,
user: process.env.databaseUser,
password: process.env.databasePassword,
port: 1433,
options: {
encrypt: true,
"enableArithAbort": true
}
};
Azure function is a packed service, its process.env
has reloaded properties of the Azure function environment, by default, it will not load your .env
file.
建议在 Azure function 应用程序设置中定义所有.env
内容:
获取此值的简单演示:
相关文档在这里看到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.