js and i'm getting error with accessing data from .env file.
my file structure looks like this: enter image description here
in .utils folder i have file mail.js where i need to access port and other data from .env
mail.js
require("dotenv").config({ path: "../.env" });
const port = process.env.email_port;
const host = process.env.email_host;
const user = process.env.email_user;
const pass = process.env.email_pass;
console.log("port", port); //undefined
getting undefined here.
Note: path is correct to .env and variable names are also correct.
CodePudding user response:
Try to add require("dotenv").config()
to the server app or to remove the { path: "../.env" }
from the require
-statement.