I had the same issue in the production environment. Sometimes the node-js server(desktop application) does not connect to firebase's real-time database from starting(installing) then after a few days I try again and it starts working. I don't know what can cause this? I tried disabling the firewall, I have allowed apps through the firewall.
when these issues occur in the production environment I switch my database to MongoDB database it always works really well.
This happed first time on my own laptop today
I was starting a new project so I have written simple code as below but was not able to connect to a real-time database for some reason but no error!
var admin = require("firebase-admin");
var serviceAccount = require("./gerneral/service.json");
admin.initializeApp({
serviceAccountId: admin.credential.cert(serviceAccount),
databaseURL: "databseurl"
});
const db = admin.database();
var ref = db.ref("data");
const connectedRef = admin.database().ref('.info/connected');
connectedRef.on('value', (snap) => {
if (snap.val() === true) {
console.log('connected');
} else {
console.error('not connected');
}
});
ref.set("it is not")
it output only ==> not connected
& not adding any value to firebase real-time database & no error
- I have used mobile JIO internet (good).
- I have disabled the firewall
- I have double-checked the service account(JSON file) and database URL and rules of the database.
I have a different project(related to the firebase Realtime database) on my PC I run that project and it running perfectly fine.
what can cause this?
how can I solve this issue?
Additional Information: I try Using this project's database in other firebase-related projects (which is working fine). It shows this project's database connecting and getting data.
so this issue is most probably related to firewall or security but I double-check after disabling the firewall so why not connect to firebase's DB?
Please anyone how to find the cause of the issue?
Thank you in advance.