Luke
Luke

Reputation: 3

Can't deploy a function to firebase because "admin.databse is not a function"

I tried to deploy this function to firebase:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

const ref = admin.databse().ref();

exports.creatUserAccount = functions.auth.user().onCreat(event =>{
    const uid = event.data.uid;
    const newUserRef = ref.child('/users/${uid}');
    return newUserRef.set({
        uid: uid
    });
});

But Node.js threw me this: "admin.databse is not a function". What should I do?

Upvotes: 0

Views: 84

Answers (2)

sungyong
sungyong

Reputation: 2499

database() is instance's function.
So you should use as below.

admin.initializeApp(functions.config().firebase);

const ref = admin.databse().ref();

to =>

var instance = admin.initializeApp(functions.config().firebase);

const ref = instance.database().ref();

Upvotes: 0

James Bob
James Bob

Reputation: 85

You made a typo, admin.databse().ref(); needs to be admin.database().ref();

Upvotes: 1

Related Questions