1

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
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?
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.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.