【发布时间】:2017-11-07 11:14:29
【问题描述】:
我正在尝试打印出我的云功能所知道的事件。我在 Atom 控制台中尝试了 console.log(event),但我得到了这个错误:
Uncaught Error: Cannot find module 'firebase-functions'
at Module._resolveFilename (module.js:455:15)
at Module._resolveFilename
我不熟悉 Javascript 或 Atom,所以我不知道为什么我没有得到预期的行为,我的猜测是我需要授权试图访问我在 Firebase 上的安全后端的脚本。
到目前为止,这是我的云功能:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPushNotification = functions.database.ref('/
iMessenger/{Messages}/{id}').onWrite(event => {
//I really want to see all that's inside of 'event'. How do I see this info??
console.log(event)
const payload = {
notification: {
title:'New message arrived',
body:'Hello World',
badge:'1',
sound:'default',
}
};
return admin.database().ref('/iMessenger/{Messages}/{id}/toUserDisplayName').once('value').then(allToken => {
if (allToken.val()){
const token = Object.keys(allToken.val());
return admin.messaging().sendToDevice(token, payload).then(response => {
});
};
});
});
【问题讨论】:
标签: node.js firebase firebase-realtime-database google-cloud-functions