I’m writing a node script to build a custom web.config file in a react app for deployment. When I run it, I want it to read in .env variables. But when I do, I get undefined for the vars. It seems to be reading in global vars fine, but not the local .env. My script is in a folder in the root project folder. How do I pull those .env variables?
3
Answers
It looks like if I run my powershell command from the root folder it finds the .env file and reads it. I was running it from the folder I had the script in.
If you’re using bash or zsh to run the script, you can do the following :
First, make .env file:
then install dotenv on your project:
then require it in your code:
then use it like that: