How to save and Access Environment Variables in Firebase - Android Hire
How-to's & guides

How to save and Access Environment Variables in Firebase

Dhaval
This is a small tutorial in which you would learn how to save and access environment variables in Firebase in Android Studio.

Now before starting this tutorial i would let you readers know about Firebase. What it is? and how it works? Remember that you need to set up firebase sdk setup before you can work upon Firebase.

What is Google Firebase?

Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011, then acquired by Google in 2014. As of March 2020, the Firebase platform has 19 products, which are used by more than 1.5 million apps. You can use this in implmentation of firebase cloud messaging too.

Save and access environment variables in firebase

What are Environment variables?

Environment variables in the cloud functions allows you to set/get key values at the time of deployment which can later be used in the code through environment variables. Firebase cloud functions also allows to specify key value pairs as config environment variables.

Environment variables can be saved by setting config set command through firebase CLI. Once Firebase project is setup you can call Firebase CLI config set function to store key value pairs.

How to save environment variables in Firebase?

Suppose you want to save database configuration in environemnt variables then it can be set by calling functions:config:set command.

firebase functions:config:set db.DB_USER="username" db.DB_PASSWORD="password" db.DB_HOST="host_url" db.DB_NAME="database_name"

How to access environment variables in Firebase?

Now after we have deployed config variables its time to see how we can use them in Firebase cloud code.

Config variables can be accessed via firebase.config() . Example of setting our database connection to external MySql database is shown in the below snippet.

const Sequelize = require('sequelize');
 const sequelize = new Sequelize(
		firebase.config().db.DB_NAME,
		firebase.config().db.DB_USER,
		firebase.config().db.DB_PASSWORD, {
			dialect: 'mysql',
			host: firebase.config().db.DB_HOST
		}, {
			pool: {
				max: 5,
				min: 0,
				idle: 20000,
				acquire: 20000
			}
		}
	)

If you want to learn via video, we found one of the good tutorial on this from Youtube.

Dhaval's profile picture

Dhaval

Dhaval is a consummate tech enthusiast with a penchant for software development and game creation. His technical prowess is reflected not only in his innovative projects but also in the insightful articles he pens. Beyond the world of technology, Dhaval immerses himself in the world of literature, indulging in novels that captivate his imagination during his leisure hours.

Related Posts

7 Top Samsung Galaxy Ring Alternatives for 2025

7 Top Samsung Galaxy Ring Alternatives for 2025

Tired of waiting for the Samsung Galaxy Ring to hit the market? You’re not alone. While the buzz around Samsung’s smart ring continues, a plethora of impressive alternatives is already available. These devices deliver advanced health tracking, stylish designs, and unique features that cater to various lifestyles. The current lineup of smart rings caters to […]

What Is Quiet Mode on Instagram and How to Activate It

What Is Quiet Mode on Instagram and How to Activate It

Ever wondered what Quiet Mode on Instagram is all about? This simple yet powerful Instagram feature helps you take a break from the constant buzz of notifications and focus on what truly matters. Whether you’re striving for better work-life balance, dedicating time to studying, or simply trying to disconnect from social media distractions, Quiet Mode […]

How to Make a Bed in Minecraft (Step-by-Step Guide)

How to Make a Bed in Minecraft (Step-by-Step Guide)

A bed in Minecraft is very important. It lets you skip the night and set your spawn point, so if you die, you will return to your bed instead of the original world spawn. This guide will show you how to gather materials, craft a bed, and set your spawn point. We’ll also show you how to customize your bed, build bunk […]

10 Best MMORPG Games For Android

10 Best MMORPG Games For Android

Not too long ago, MMORPG games and powerful gaming consoles were mostly exclusive to PCs. They required high-end graphics and systems to deliver their immersive gameplay. But times have changed. With the rise of gaming-oriented smartphones, you can now enjoy PC-like gaming experiences on your Android device. Thanks to these technological advancements and faster internet […]

Roblox: Fruit Battlegrounds codes (January 2025)

Roblox: Fruit Battlegrounds codes (January 2025)

Fruit Battlegrounds codes are all about getting more gems and help you to shoot up your rank in this One Piece anime-inspired game. This Fruit Battlegrounds was made by Popo developer. It is an action-packed game where players battle it out using unique fruit-based abilities. With constant updates, new fruits, and exciting challenges, it’s a fruity frenzy you won’t […]

Roblox: Ultimate Football Codes (January 2025)

Roblox: Ultimate Football Codes (January 2025)

Want to get some extra items for Ultimate Football in Roblox? You’ve come to the right place! Here’s the latest list of codes to help you score touchdowns and look stylish on the field. These codes offer free rewards such as coins and cosmetics to enhance your gameplay. What are Ultimate Football Codes? Ultimate Football […]

Roblox: Da Hood Codes (January 2025)

Roblox: Da Hood Codes (January 2025)

Are you a fan of Roblox games, in this article we will look at the Roblox Da Hood Codes for December 2024 that will help you unlock exclusive items, improve your gameplay and dominate the streets of Da Hood. You can feel that the game is inspired by the Grand Theft Auto series and there […]