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:
我正在使用云功能,并希望从我的一个Javascript服务器文件中获取项目名称。我知道该值存储在.firebaserc中,但我不认为该文件在服务器上可用,对吧?我想做这样的事情:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.getProjectName(); // or getProjectID()
or
functions.getProjectName();
3 个解决方案
#1
10
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.
谢谢@Frank。答案是:process.env.GCLOUD_PROJECT。我不确定变量过程的来源,但这确实可以获得项目名称。
#2
1
Firebase admin SDK has access to that information for you.
Firebase管理员SDK可以为您访问该信息。
const admin = require('firebase-admin');
const projectId = admin.instanceId().app.options.projectId
#3
-4
You can use functions.config().firebase.projectId
您可以使用functions.config()。firebase.projectId
PS the easiest way to initialize app is admin.initializeApp(functions.config().firebase);
PS初始化应用程序的最简单方法是admin.initializeApp(functions.config()。firebase);
#1
10
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.
谢谢@Frank。答案是:process.env.GCLOUD_PROJECT。我不确定变量过程的来源,但这确实可以获得项目名称。
#2
1
Firebase admin SDK has access to that information for you.
Firebase管理员SDK可以为您访问该信息。
const admin = require('firebase-admin');
const projectId = admin.instanceId().app.options.projectId
#3
-4
You can use functions.config().firebase.projectId
您可以使用functions.config()。firebase.projectId
PS the easiest way to initialize app is admin.initializeApp(functions.config().firebase);
PS初始化应用程序的最简单方法是admin.initializeApp(functions.config()。firebase);