After creating a new web app with create-react-app (CRA)
, I need to include some environment files for configuring various endpoints. Noticed that CRA comes with the cool dotenv
package all ready to go. There's only one problem with that - I would like to have dotenv
read these files from within my ./environments
directory and not the root directory. Is there any way to load the .env
, .env.local
, .env.test
, etc... files in a directory separate from the root directory?
Noticing I can achieve this in my express backend server.js
by simply importing like so:
require('dotenv').config({ path: `./environments/` })
Can I do the same with my client-side code in React? If so, where should I put this import? Doesn't seem to work for me.