Deploy Firebase Apps to Different Environments

Use different configs for each of your Firebase environments

You can use Firebase’s env config variables, but I find them difficult to manage. More than once I used prod variables in dev!

dotenv to the rescue

Here is what I do to create a staging and production environments with different configurations in Firebase.

1. Setup a unique Firebase project for each environment, e.g. Production, Staging, and Development.

2. At a command prompt, assign an alias for each project with:

firebase use --add

3. Create a different .env file for each environment: .env.production, .env.staging, .env.development. Place your specific configs for those environments there.

4. Install “dotenv” with:

npm i --save-dev dotenv

This is assuming your using NodeJS. dotenv is a fantastic way to manage environment configs in node.

5. Add a build script “build-staging” to your package.json file (or build-dev):

"build-staging": "dotenv -e .env.staging react-scripts build"

6. Build with the script:

npm run build-staging

7. Deploy to Firebase:

firebase deploy -P staging


Thank you for reading. 🙏

About Author

Geoffrey Bourne is co-founder of Ayrshare, an API-first platform to automate your social media posts with a few lines of code.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store