dotenv文件未加载环境变量 [英] dotenv file is not loading environment variables
问题描述
我在根文件夹文件
NODE_ENV=development
NODE_HOST=localhost
NODE_PORT=4000
NODE_HTTPS=false
DB_HOST=localhost
DB_USERNAME=user
DB_PASSWORD=user
和 And 我还尝试了以下操作: 但是,当我运行 However, my env variable are not loaded when I run the 如果我使用 visual studio 并按 F5 ,它将加载! If I use the visual studio and press F5, it loads!! 我不确定我在做什么错,我想念什么.
任何建议都将受到高度赞赏.谢谢. I'm not sure what I'm doing wrong, what I'm missing.
Any suggestion is highly appreciate. Thanks. 使用 您的问题似乎是执行路径. Your problem seems to be the execution path. 这篇关于dotenv文件未加载环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!server.js
文件.
server.js
文件的第一行是server.js
file in the root/app/config/server.js
folder.
The first line of server.js
file is require('dotenv').config();
require('dotenv').config({path: '../.env'})
; require('dotenv').config({path: '../../.env'})
; server.js
文件时,不会加载我的env变量
从命令提示符 server.js
file
from command promptnode root/app/config/server.js
推荐答案
require('dotenv').config({path:__dirname+'/./../../.env'})
如何?