There's a requirement to switch between production/development environment while app is running (in development mode). I'm using react-native-dotenv third-party in order to support .env files. I've found a solution that it's possible in nodejs environment like this approach. does anyone know that how is that possible in react native? or is there any other clean alternative?
Asked
Active
Viewed 1,448 times
1 Answers
3
This feature is already built-in react-native-dotenv
. Here is the precise Link for official documentation. In addition, it's completely up to you how you manage multiple .env files. You can use either dotenv-flow or react-native-dotenv.

Asmat ullah
- 681
- 8
- 23
-
Thank you so much, but the requirement is to switch between the .env files in run time (while app is running). is there any solution for that? – Aliunco Oct 18 '22 at 17:55
-
Do you want to change .env while the app is in the production phase like a signed APK or do you want to change it while app is connected to the local server? – Asmat ullah Oct 19 '22 at 12:46
-
No! (thanks for following). let me rephrase it again. while the app is running in the development mode (like running via Expo go), I need to switch between the production and development environments (without restarting the bundler) so the testers can switch between them and test the app. – Aliunco Oct 19 '22 at 15:07
-
As far as I know, it's kind of impossible (at least for me) because every time we do a change in .env which is in .gitignore we have to tell the metro server manually to publish changes to the App. You could manipulate .env with a component that will change the required .env to `dev` or `prod` at run time via the toggle button in a separate screen(just for testing purposes). i.e `toggle===off ? setStates of dev : setStates of prod` – Asmat ullah Oct 20 '22 at 09:03