I have .env file at root folder file
NODE_ENV=development
NODE_HOST=localhost
NODE_PORT=4000
NODE_HTTPS=false
DB_HOST=localhost
DB_USERNAME=user
DB
I've had this problem and it turned out that REACT only loads variables prefixed with REACT_APP_
VueJs can have a similar issue as it expects variables to be prefixed with: VUE_APP_
In my case .env
was read fine, but not .env.local
.
Updating package.json
to name .env
into .env.local
( cp ./.env.local .env
) solved the problem:
"myscript": "cp ./.env.local .env && node ./scripts/myscript.js"
In the remote case that you arrive till this point, my issue was quite dumber: I wrongly named my env variables with colon ":" instead of equals "=". Rookie mistake but the resulting behavior was not loading the misspelled variables assignment.
# dotenv sample content
# correct assignment
USER=sample@gmail.com
# wrong assignment (will not load env var)
USER : sample@gmail.com