Preview:
// env.js file

import { DEV_BACKEND_URL, PROD_BACKEND_URL } from "@env";

const devEnviromentVariables = {
	DEV_BACKEND_URL,
};

const prodEnviromentVariables = {
	PROD_BACKEND_URL,
};

export default __DEV__ ? devEnviromentVariables : prodEnviromentVariables;


// babel.config.js file
module.exports = {
	presets: ["module:metro-react-native-babel-preset"],

	plugins: [
		[
			"module:react-native-dotenv",
			{
				envName: "APP_ENV",
				moduleName: "@env",
				path: ".env",
			},
		],
	],
};


// File requiring the variables

import envs from "../config/env";
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter