Nodejs express firebase (event 'value' tidak terpanggil di backend)

Halo saya kesulitan mendapatkan akses ke realtime database di firebase dari backend nodejs express nih, tidak ada error tapi event companyRef.on('value') tidak pernah terpanggil meskipun db diubah2. SOURCE CODE :

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

// admin.initializeApp({
//     credential: admin.credential.applicationDefault(),
//     databaseURL: 'https://myapp.firebaseio.com'
// });
// var serviceAccount = require("./skey.json");
// admin.initializeApp({
//     credential: admin.credential.cert(serviceAccount),
//     databaseURL: 'https://myapp.firebaseio.com'
// });

var db = admin.database();
var companyRef = db.ref('company');
console.log('db initialized... ');
companyRef.on("value", function (items) {
    console.log('items changing : ' + items.val()); //never called? even realtime db changed??
});

CONSOLE :

PS C:\vswork> firebase serve --only functions,hosting
 functions: Using node@10 from host.
 functions: Emulator started at http://localhost:5001
i  functions: Watching "C:\vswork>\functions" for Cloud Functions...
i  hosting: Serving hosting files from: public
 hosting: Local server: http://localhost:5000
!  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to C:\Users\guest1\Downloads\skey.json. Non-emulated services will access production using these credentials. Be careful!
>  db initialized...
 functions[app]: http function initialized (http://localhost:5001/myapp/us-central1/app).

tapi klo saya panggil via javascript atau tag <script> di halaman html atau hbs tidak masalah.

bagaimana jika data memang mau diambil dari backend(express) dan dikirim ke handlebars template, atau jika tidak keberatan ada video lanjutannya dari modul 'forum' di : https://www.youtube.com/watch?v=6cQIN5la1_g&list=PLCZlgfAG0GXCMaYN4ZYiuyHRG5KSGd2la&index=11&t=0s

terima kasih ya sebelumnya.

avatar santio
@santio

1 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban