使用新的firebase-admin for NodeJS我得到firebase-admin error No Firebase app named '" + appName + "' exists
错误,包含新旧凭据和2种不同样式的initializeApp
Error: No Firebase app named '[DEFAULT]' exists.
var admin = require("firebase-admin");
var db = admin.database();
var ref = db.ref();
admin.initializeApp({
credential: admin.credential.cert({
projectId: "projectId",
clientEmail: "firebase-adminsdk@iam.gserviceaccount.com",
privateKey: "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhuPuR\nDAoyxH9OiC1CaSJ8/GquyVvQGvCcsXQAGh2LX2uSXKzycuDGAoUkb2Nhc4dk0/Nm\nLNudSRHCku2h2df0v7z65YXt\n-----END PRIVATE KEY-----\n"
}),
databaseURL: process.env.DATABASEURL
});
node_modules / firebase- 管理/ LIB /火力-namespace.js:52:19
答案 0 :(得分:0)
const adm = require ('firebase-admin');
adm.initializeApp(func.config().firebase);
这是初始化firebase数据库的一种方法,可以清除上述错误。