Error in FIREBASE + NODEJS: Firebase App named '[DEFAULT]' already exists

2

I have a CRUD made with NODEJS + EXPRESS using FIREBASE.

I add a record normally, but when I add the next, it gives me the error:

[DEFAULT]: Firebase: Firebase App named '[DEFAULT]' already exists (app / duplicate-app).

If I restart the server, it works. From what I've seen, I'm triggering the connection multiple times, but I do not know where to fix this.

Can you explain?

var fb = this._firebase.database();

var result = fb.ref().child('clientes/').orderByChild('empresa').equalTo(cliente.cnpj);
result.once('value').then(function(snapshot){

    var erros;
    if(snapshot.length < 0){
        erros = { 
            erro: 'CNPJ já cadastrado.'
        };
        return erros;
    }

    var key = fb.ref('clientes/').push(cliente).key;

    var mensagem = {
        msg: 'Cliente cadastrado com sucesso!',
        status: 'success'
    }

    res.render('clientes/clientes', { validacao: {}, dadosForm: {}, mensagem: mensagem });
});
    
asked by anonymous 11.03.2017 / 19:17

1 answer

1

This error usually occurs when the

firebase.initializeApp(firebaseConfig)

is called more than once. Check where the call is occurring, if it is not in a loop, or if it is being called whenever a new request is made.

    
05.07.2017 / 22:49