I have a project with folder structure is as follows,
Root > client, server
I want to use the environment variables form the .env file of my Root directory in the /Server/src, But when I try to import it in /Server/src the environment variables are undefined.
Is there a way to use those environment variables in the Server directory?
// from Root directory
const dotenv = require("dotenv");
dotenv.config();
module.exports = {
NODE_ENV: process.env.NODE_ENV,
}
// from Server directory
const { NODE_ENV,} = require("./config");
console.log(NODE_ENV); //value returns undefined