【问题标题】:dotenv not loading .env filedotenv 未加载 .env 文件
【发布时间】:2018-06-05 22:40:37
【问题描述】:

使用 dotenv 库,我无法从我的节点项目访问 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

【问题讨论】:

    标签: javascript node.js


    【解决方案1】:

    在 .env 文件中不等于冒号!

    JIRA_CONSUMER_KEY=bot-consumer-key
    

    否则你没有字典!

    【讨论】:

    • @Wuzza 最好给罗伯特,正确的答案检查:)
    猜你喜欢
    • 2020-09-05
    • 2021-11-08
    • 2020-01-31
    • 2017-06-25
    • 2017-07-09
    • 1970-01-01
    • 2022-10-01
    • 2020-03-07
    • 2017-07-06
    相关资源
    最近更新 更多