How to get Firebase Project Name or ID from Cloud Function

后端 未结 6 1368
别跟我提以往
别跟我提以往 2021-01-01 12:25

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

相关标签:
6条回答
  • 2021-01-01 12:41

    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.

    0 讨论(0)
  • 2021-01-01 12:42

    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)

    0 讨论(0)
  • 2021-01-01 12:49

    try this :

    const projectId = admin.instanceId().app['options_'].credential.projectId
    
    0 讨论(0)
  • 2021-01-01 13:02

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

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

    0 讨论(0)
  • 2021-01-01 13:05

    Firebase admin SDK has access to that information for you.

    const admin = require('firebase-admin');
    const projectId = admin.instanceId().app.options.projectId
    
    0 讨论(0)
  • 2021-01-01 13:06

    This worked for me. (node 10)

    const FIREBASE_CONFIG = process.env.FIREBASE_CONFIG && JSON.parse(process.env.FIREBASE_CONFIG);
    const projectId = FIREBASE_CONFIG.projectId;
    
    0 讨论(0)
提交回复
热议问题