A Firebase application named "[DEFAULT]" already exists, and the google firebase link does not work on the server

I have completed all the steps for configuring the server in https://firebase.google.com/docs/database/server/retrieve-data#section-start , but when I try to create a link in the browser, they tell me that the application with the name [default ] already exists. At that time, if preiono F5 tells me that there is a "databaseUrl", I must provide this data when starting the firebase application.

var express = require('express'); var router = express.Router(); var firebase = require('firebase'); /* GET home page. */ router.get('/', function(req, res, next) { firebase.initializeApp({ serviceAccount: "aaaabbbbcccc.json", databaseUrl: "https://xxxxxyyyyyzzzzz.firebaseio.com/" // <<<<--- it can not find }); var db = firebase.database(); // <<<<---- Here is a problem var ref = db.ref('vistas/principal'); ref.once('value', function(data){ res.render('index', { title: 'Express' }); }); }); module.exports = router; 

I created other authorizations, other keys, etc. But nothing works. Thanks.

Node -v = v4.2.6 Firebase v3.x

 FIREBASE FATAL ERROR: Can't determine Firebase Database URL. Be sure to include databaseURL option when calling firebase.intializeApp(). Error: FIREBASE FATAL ERROR: Can't determine Firebase Database URL. Be sure to include databaseURL option when calling firebase.intializeApp(). at Error (native) at ad (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\firebase\database-node.js:37:278) at Object.firebase.INTERNAL.registerService.Reference [as database] (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\firebase\database-node.js:238:113) at Ou (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\firebase\app-node.js:16:94) at Object.d [as database] (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\firebase\app-node.js:18:182) at c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\routes\index.js:14:21 at Layer.handle [as handle_request] (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\express\lib\router\layer.js:95:5) at next (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\express\lib\router\route.js:131:13) at Route.dispatch (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (c:\TsPrj\_pruebas\vistas-realtime-desde-firebase\node_modules\express\lib\router\layer.js:95:5) 
+7
reference firebase firebase-database
source share
3 answers

You can check if the application is downloaded since it needs to be downloaded once. One of the methods:

 if (!firebase.apps.length) { firebase.initializeApp({}); } 
+6
source share

here is the answer i wrote for this question

This is a problem I encountered, as well as updating to a new version of Firebase. You might want two separate firebase applications to be initialized, but I just wanted to use refs in two different places in my application, and I was getting the same error.

What you need to do for this situation is to create a firebase module for your application that only initializes firebase once, then you import or require it elsewhere in your application.

You need to copy the entire configuration object from the firebase console and paste it here using the API key and that's it.

Here is an example of how I created my module: modules / firebase.js

 import firebase from 'firebase'; var firebaseConfig = { apiKey: "some-api-key", authDomain: "some-app.firebaseapp.com", databaseURL: "https://some-app.firebaseio.com", storageBucket: "some-app.appspot.com", }; var FbApp = firebase.initializeApp(firebaseConfig); module.exports = FbApp.database(); //this doesnt have to be database only 

And then elsewhere in your application, you simply:

 import Firebase from '/your/module/location' var messagesRef = Firebase.ref("messages/"); 

or

 var Firebase = require('/your/module/location'); var messagesRef = Firebase.ref("messages/"); 
+4
source share

You have to execute firebase.initializeApp only ONCE per application, outside of your router.get By the way, your export looks strange / wrong ... if this is a module, why do you call router.get directly? As soon as you need your module, it will be executed. Why are you exporting a router?

0
source share

All Articles