【发布时间】:2018-05-23 11:39:03
【问题描述】:
使用 node.js 为我的带有 firebase 的 android 聊天应用程序项目创建推送通知。当我在通知功能上部署我的 firebase 时,出现了一些错误。
这是我的 index.js 在 38 : 11 和 39:16 ****这是我的 index.js****
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/notification/{user_id}/{notification_id}').onWrite(event => {
const user_id = event.params.user_id;
const notification = event.params.notification;
console.log("The User Id is : ",user_id);
if(!event.data.val()){
return console.log('A Notification has been deleted from database : ', notification_id);
}
const fromUser = admin.database().ref(/notification/${user_id}/{notification_id}).once(value);
return fromUser.then(fromUserResult => {
const from_user_id = fromUserResult.val().from;
console.log('You have new notification from : ', from_user_id);
const userQuery = admin.database().ref(`/Users/${user_id}/${notification_id}`).once('value');
return userQuery.then(userResult => {
const userName = userResult.val();
const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
return deviceToken.then (result => {
const token_id = result.val();
const payload = {
notification : {
title : "Friend Request",
body : `${userName} has sent you request`,
icon : "default"
}
};
return admin.messaging().sendToDevice(token_id , payload);
});
});
});
});
**The cmd give me following result**
C:\Users\Ouneeb Ur Rehman\Desktop\notification function\functions\index.js
19:40 error Parsing error: Invalid regular expression flag
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ouneeb Ur Rehman\AppData\Roaming\npm-cache\_logs\2018-05-23T11_05_23_181Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit
I try install and uninstall npn and firebase tools but alls goes to vane
我得到了 firebase 令牌 ID 并存储在数据库中 我是节点 js 的新手,不能 uenter image description here 请任何人都可以提供帮助 提前致谢
这是我的通知数据库 sinpit
【问题讨论】:
-
请编辑您的问题以准确显示错误消息。
标签: javascript firebase google-cloud-functions