RN - Configure environment variables for Dev and Prod

PHOTO EMBED

Sat Nov 13 2021 17:09:57 GMT+0000 (UTC)

Saved by @TheInspired #javascript

// 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";
content_copyCOPY