How do I know if my React Native app is running in production or development? Is there some sort of way within JavaScript to tell? Is there a global that is passed in?
-
FYI, I was getting this when importing a Component in `react-native` in my `globalSetup` file. Moving this setup from `globalSetup` to `setupFilesAfterEnv` did the trick, since the `jest` test environment is loaded before the files listed in `setupFilesAfterEnv` are run. – Joshua Pinter May 25 '21 at 21:22
4 Answers
You can use the __DEV__
global variable in JavaScript to determine if you're using React Native packager or not. If you are running your app in the iOS Simulator or Android emulator __DEV__
will be set to true
.
-
20Also if you are running the app on a physical device using `react-native run-*` – Ricardo Stuven Aug 13 '16 at 17:17
-
15What about when you run in a simulator with `--configuration Release`? Does this still use the React Native packager and set `__DEV__` to `true`? – Marklar Nov 16 '18 at 04:46
-
1@Marklar when running in release configuration, the `__DEV__` is NOT set to true in my experience. – Tope Apr 09 '19 at 12:24
-
`__DEV__` is only about the build configuration. If you want to detect whether the app is running on device or in a simulator, use something like `react-native-device-info`. – Tamlyn May 24 '23 at 10:54
You can use the __DEV__
variable.
By default if you run your app with npx react-native run-ios
or npx react-native run-android
, it will run in Debug mode and __DEV__
will be true.
In release mode, __DEV__
will be false.
You can use it this way:
const CLOUD_API_BASE_URL = __DEV__ ? 'https://api-dev.yourdomain.com' : 'https://api-prod.yourdomain.com';
You can run the app in Release mode with the terminal:
react-native run-android --variant release
#android
react-native run-ios --configuration Release
#ios
Or open the ios folder in XCode, choose Product > Scheme > Edit Schemes
Select Run in the left menu. For Build Configuration, choose 'Release' and uncheck 'Debug executable'
In Android Studio, similarly, you can set the build variant to release

- 2,352
- 24
- 26
-
2what if I have multiple variant (uat , sit, prod ) and not just simple (debug or release) , I want to know exactly where is that piece of toggle in build gradle turning __DEV__ true or false , i cannot find any resource telling me to do this – elliotching Apr 12 '22 at 09:24
When the __DEV__
variable is set to true
, it turns on a bunch of useful development warnings. For production, it is recommended to set __DEV__=false
.

- 955
- 11
- 11
-
1
-
4
-
You didn't specify anyway to go about this. How does someone set to false? – Alexander Oct 27 '22 at 21:31
I didn't intend to write an answer, but I'm not able to comment (<50 pts). To toggle __DEV__
, you can set it before your command, e.g.:
__DEV__=true expo start
(should already be set to true though)
or
__DEV__=false react-native run-ios
(should be set to true by default, when running this command without setting manually)

- 1
- 2
-
1All other answers already made that clear. Even a comment wasn't necessary. – Gert Arnold Feb 02 '23 at 18:34
-
Does this work for you? It doesn't for me. `__DEV__` is not a normal environment variable so it can't be set like this. – Tamlyn May 24 '23 at 10:50