How to use app.config.js with environment variable?

Please provide the following:

  1. SDK Version: 41.0.0
  2. Platforms(Android/iOS/web/all): all
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

Hi, I’m having trouble understanding the section Switching configuration based on the environment in order to publish the staging/prod app.config.js.

In the above paragraph, the app.config.js is using: export default ({ config }) => {
But in the later it use module.exports = () => {

I’m quite newbie in js so not exactly how to combine them into works, this is how I’m putting them at the moment, would it works if I try to do MY_ENVIRONMENT=production expo publish?:

const stagingConfig = ({ config }) => {
  const appConfig = {
    ...config,
    version: 1,
    // override anything you want
    extra: {
      API_URL: "my staging url",
      AndroidGoogleServicesFile: "staging googleservice file",
      // ...
    },
  }
  return appConfig
}

const prodConfig = ({ config }) => {
  const appConfig = {
    ...config,
    version: 2,
    // override anything you want
    extra: {
      API_URL: "my prod url",
      AndroidGoogleServicesFile: "prod googleservice file",
      // ...
    },
  }
  return appConfig
}

module.exports = () => {
  if (process.env.MY_ENVIRONMENT === "production") {
    return prodConfig
  } else {
    return stagingConfig
  }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.