我正在使用 dotenv 加载环境变量,但它没有加载它们。即使我在 .env 文件中定义了它们,它也会给出
undefined
。
index.js中的代码在这里:
我什至尝试了以下要求:
require('dotenv').config();
require('dotenv').config({path:'C:\Users\xuios\Desktop\AirlineManagementProject\FlightsAndSearch\src\.env'});
// 绝对路径
require('dotenv').config({path:'FlightsAndSearch\src\.env'});
//相对路径
我通常这样做,到目前为止它有效
const env = require('dotenv');
env.config();
然后加载
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS,