简体   繁体   中英

How do I get the default bucket name in Firebase, from inside Node.js?

I want to avoid hard coding the default bucket name in a Firebase project. How do I get it on server side?

const admin = require("firebase-admin");
const defaultBucket = admin.storage().bucket();
const defaultBucketName = ...?

Get bucket name:

const defaultBucketName = defaultBucket.name;

Ref: Interface: ObjectMetadata

It turns out that the information is stored in an environment variable but not imported into the admin tooling directly. So the best way I have found to prepare your environment to serve the default bucket name is as follows:

const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG!);

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  storageBucket: firebaseConfig.storageBucket,
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM