使用 dotenv 库,我无法从 Node 项目访问 process.env 变量。
index.js(入口点)
const result = require('dotenv').config()
if (result.error) {
throw result.error
}
console.log(result.parsed)
console.log(process.env.JIRA_CONSUMER_KEY);
.env
JIRA_CONSUMER_KEY:bot-consumer-key
命令行输出
⇒ nodemon index.js
[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
{}
undefined
undefined
文件树
- icm_bot
- index.js
- .env
最佳答案
.env 文件中的等于而不是冒号!
JIRA_CONSUMER_KEY=bot-consumer-key
否则你就得不到字典!
关于javascript - dotenv 未加载 .env 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47955692/