Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Firebase Project Name or ID from Cloud Function

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 think that 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();  
like image 914
Coder1224 Avatar asked May 19 '17 19:05

Coder1224


People also ask

How to find project ID Firebase?

Using the Firebase console: Click settings Project settings. The project ID is displayed in the top pane. Using the Firebase CLI: Run firebase projects:list . The project ID is displayed along with all the Firebase projects associated with your account.

How do I find project ID in cloud?

You can get project ID as const projectId = process. env. GCP_PROJECT .

How to change Firebase project name?

You can just delete the current project, make a new project, download its google-services. json file and replace it with the current one in your app folder then finally you'll have to clean your project from Build -> CleanProject! That's it!


2 Answers

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.

like image 130
Coder1224 Avatar answered Sep 18 '22 11:09

Coder1224


Firebase admin SDK has access to that information for you.

const admin = require('firebase-admin'); const projectId = admin.instanceId().app.options.projectId 
like image 25
Hugo Silva Avatar answered Sep 18 '22 11:09

Hugo Silva