Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase cloud function process.env.FIREBASE_CONFIG.projectId is undefined

From Firebase official docs on cloud functions:

https://firebase.google.com/docs/functions/config-env#automatically_populated_environment_variables

enter image description here

I need to access the projectId, so I'm trying:

type FirebaseConfigEnv = {
  databaseURL: string,
  storageBucket: string,
  projectId: string
}

export const helloWorld = functions.https.onRequest((request, response) => {
  const FIREBASE_CONFIG = process.env.FIREBASE_CONFIG as unknown as  FirebaseConfigEnv;
  response.send(`FIREBASE_CONFIG.projectId: ${FIREBASE_CONFIG.projectId}`);
});

And I'm getting on the browser the following result:

enter image description here

Why is the process.env.FIREBASE_CONFIG object not being properly populated on my runtime environment?

like image 438
cbdeveloper Avatar asked Oct 15 '25 14:10

cbdeveloper


1 Answers

The value of process.env.FIREBASE_CONFIG is a JSON string. As strings do not have a property called projectId, you get undefined.

To use it like you expect, you must first parse it as shown at the bottom of the documentation you linked:

const FIREBASE_CONFIG = JSON.parse(process.env.FIREBASE_CONFIG);
const projectId = FIREBASE_CONFIG.projectId;
like image 83
Raphael PICCOLO Avatar answered Oct 17 '25 07:10

Raphael PICCOLO