dotenv没有加载.env文件

0 javascript node.js

使用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);
Run Code Online (Sandbox Code Playgroud)

.ENV

JIRA_CONSUMER_KEY:bot-consumer-key
Run Code Online (Sandbox Code Playgroud)

命令行输出

?  nodemon index.js
[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
{}
undefined
undefined
Run Code Online (Sandbox Code Playgroud)

文件树

- icm_bot
    - index.js
    - .env
Run Code Online (Sandbox Code Playgroud)

Rob*_*kal 5

它等于.env文件中的冒号!

JIRA_CONSUMER_KEY=bot-consumer-key
Run Code Online (Sandbox Code Playgroud)

否则你没有字典!

  • @Wuzza 如果能给 Robert 检查正确答案就好了:) (2认同)