Reputation: 3150
When using the Firebase Node.js SDK to write data, I get net::ERR_CONNECTION_REFUSED
in the browser and The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
in the console. Yet when I use the old way, it works.
New code:
var admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.cert("<my-account>.json"),
databaseURL: "https://<my-project>.firebaseio.com"
});
Old code (working):
var admin = require("firebase-admin");
firebase.initializeApp({
serviceAccount: "<my-config>.json",
databaseURL: "https://<my-project>.firebaseio.com"
});
I get the deprecation warning when using the old code, but it writes to Firebase nonetheless.
What could I be missing?
Upvotes: 1
Views: 903
Reputation: 1454
This worked for me with the newer version of Firebase:
var functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
Upvotes: 1