Deploy Firebase Apps to Different Environments

Use different configs for each of your Firebase environments

Geoffrey Bourne
Feb 26 · 2 min read

Google’s Firebase is a great system and environment to quickly build web apps. However, there are a few tricky things to work around, such as deploying to different 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


Check out other Firebase stories at or our Firebase Newsletter.

Also if you’re concerned about your Firebase costs (or have been burned by them in the past), check out 🔥🔥 to help manage and control your Firebase usage costs.

Geoffrey Bourne

Written by

ceo & founder of RETIRETY ( — helping you find a better retirement

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade