My react app is running on http://localhost:3000 and I wanted to setup the env variable for the different environment development, production, staging and local.
my react app url for different environment are(I am mocking my urls)
local = http://localhost:3000 development = http://react.developmet.com production = http://react.production.com stage = http://react.stage.com looking for a solution how i can setup the env var for different environment.
Adding my approach to the same thing just wanted to know is this approach is good or not.
and how I can achieve same for staging environment
I have created an environment.js file.
let BASE_URL = http://localhost:3000 //check for environment if (process.env.REACT_APP_ENV = "development") { BASE_URL = "http://react.developmet.com" } if (process.env.REACT_APP_ENV = "production") { BASE_URL = "http://react.production.com" } export {BASE_URL} and also updated my run scripts
"scripts": { "dev":"REACT_APP_ENV=development npm start", "prod":"REACT_APP_ENV=productionnpm start", "build:dev":"REACT_APP_ENV=development npm run-script build", "build:prod":"REACT_APP_ENV=production npm run-script build", }