I am using Cloud Functions and want to get the project name from within one of my Javascript server files. I know that value is stored in the .firebaserc, but I don\'t thin
Thank you @Frank. The answer is:
process.env.GCLOUD_PROJECT
.
I'm not sure where the variable process
comes from, but this does work to get the project name.
Currently I'm using app.INTERNAL.credential_.projectId
.
This is clearly not save, but so far there is no cohesive way to get it (AFAIK)
try this :
const projectId = admin.instanceId().app['options_'].credential.projectId
You can use functions.config().firebase.projectId
PS the easiest way to initialize app is admin.initializeApp(functions.config().firebase);
Firebase admin SDK has access to that information for you.
const admin = require('firebase-admin');
const projectId = admin.instanceId().app.options.projectId
This worked for me. (node 10)
const FIREBASE_CONFIG = process.env.FIREBASE_CONFIG && JSON.parse(process.env.FIREBASE_CONFIG);
const projectId = FIREBASE_CONFIG.projectId;