I'm trying to get a print out of the events my cloud function is privy to. I tried console.log(event)in the Atom console but I get this error:
我正试图打印出我的云功能所知道的事件。我在Atom控制台上尝试了console.log(event),但是我收到了这个错误:
Uncaught Error: Cannot find module 'firebase-functions'
at Module._resolveFilename (module.js:455:15)
at Module._resolveFilename
I'm not familiar with Javascript or Atom, so I don't know why I'm not getting the expected behaviors, my guess is that I need to authorize the script that is trying to access my secure backend on Firebase.
我不熟悉Javascript或Atom,所以我不知道为什么我没有得到预期的行为,我的猜测是我需要授权试图在Firebase*问我的安全后端的脚本。
Here's my cloud function so far:
到目前为止,这是我的云功能:
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 => {
});
};
});
});
2 个解决方案
#1
0
using console.dir(event)
will list every available method and parameter within event
使用console.dir(event)将列出事件中的每个可用方法和参数
#2
0
Console.log(event) shows up in your cloud function logs in firebase. And the missing module was because my editor couldn’t exactly interface with the firebase modules I figure, as firebase accepts my functions and the notification are coming through; a testament to successful implementation.
Console.log(事件)显示在firebase中的云功能日志中。缺少的模块是因为我的编辑器无法与我认为的firebase模块完全接口,因为firebase接受了我的功能并且通知正在通过;成功实施的证明。
#1
0
using console.dir(event)
will list every available method and parameter within event
使用console.dir(event)将列出事件中的每个可用方法和参数
#2
0
Console.log(event) shows up in your cloud function logs in firebase. And the missing module was because my editor couldn’t exactly interface with the firebase modules I figure, as firebase accepts my functions and the notification are coming through; a testament to successful implementation.
Console.log(事件)显示在firebase中的云功能日志中。缺少的模块是因为我的编辑器无法与我认为的firebase模块完全接口,因为firebase接受了我的功能并且通知正在通过;成功实施的证明。