I have declared some environment variables on my server using dotenv
, and I want to be able to access one of them on my client-side code
I have my .env file set up like so:
NODE_ENV='development'
DEF_USER='admin'
then I have my config.js
file where I load the variables from my env file:
const dotenv = require('dotenv');
const path = require('path');
dotenv.config({
path: path.resolve(__dirname, `../environments/${process.env.NODE_ENV.trim()}.env`)
});
module.exports = {
NODE_ENV: process.env.NODE_ENV || 'development',
DEF_USER: process.env.DEF_USER || 'admin'
};
How can I acces my DEF_USER
variable on my client's code? I can access NODE_ENV
with process.env.NODE_ENV
, but no such luck with DEF_USER
.
I should mention that my server and my client code is in separate directories.
Also, I didn't used create-react-app
.
I also tried by installing webpack
in my client but it trows me a lot of errors.