this is my code
admin.initializeApp({...});
var db = admin.database();
let ref = db.ref(...);
await ref.once("value",function () {...},);
firebase.database().goOffline();
firebase.database().goOnline();
ref.on("value",function () {...},);
);
when i use firebase.database().goOnline(); I get an error
Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
at app
You're mixing two ways of addressing Firebase.
You can access Firebase through:
firebase
.admin
.Now you initialize admin
, but then try to access firebase.database()
. And since you did call admin.initializeApp
that's where the error comes from.
My guess is that you're looking for admin.database().goOnline()
or db.goOnline()
.
Also note that there is no reason to toggle goOffline()
/goOnline()
in the way you do now, and you're typically better off letting Firebase manage that on its own.