How to get name or id of Firebase project from cloud function

I am using Cloud Functions and I want to get the project name from one of the Javascript server files. I know the value is stored in .firebaserc, but I don't think the file is available on the server, right? I want to do something like this:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.getProjectName();  // or getProjectID()

      

or

functions.getProjectName(); 

      

+3


source to share


3 answers


Thanks @Frank. Answer: process.env.GCLOUD_PROJECT

.
I'm not sure where the variable is coming from process

, but this works to get the project name.



+5


source


The Firebase admin SDK has access to this information for you.



const admin = require('firebase-admin');
const projectId = admin.instanceId().app.options.projectId

      

0


source


you can use functions.config().firebase.projectId

PS the easiest way to initialize an application is admin.initializeApp(functions.config().firebase);

-3


source







All Articles