0

I have deployed my MERN app on aws ec2 ubuntu and I am using dotenv to load my environment variables, using pm2 for the server and also using nginx.

In the server I am trying to load the values on my .env file which sits in the server directory, and read it into the client directory.

When printing this these values to the console from the client, it shows me only one old values which is the NODE_ENV variable. All other values printed are undefined.

I cant seem to reload anything.

I have tried to do the following separately: delete the server running in pm2. pm2 restart all --update-env pm2 restart <pid> --update-env pm2 reload Reboot the aws instance. pm2 reload ecosystem.json --update-env which is not found.

And also trying to configure the path into dotenv.config({path: ...})

Nothing worked for me, who can help me with this issue please ?

Joshua
  • 1,005
  • 1
  • 11
  • 16

1 Answers1

0

I had to add another .env file to the root of my client folder for React

And name all variables in the .env file with REACT_APP_

This React page should help: https://create-react-app.dev/docs/adding-custom-environment-variables/

Joshua
  • 1,005
  • 1
  • 11
  • 16