我已经制作了一个脚本来向我的 Firebase 服务器发送推送通知,但是 javascript eslint 首先为 const 抛出错误。
然后我在 Google 上发现我必须将 ecmaVersion = 6 放在我的 .eslintsrc 文件中。我这样做了,然后它在要求、导出和控制台字段上显示错误。
我使用 Atom 作为我的代码编译器。这是我的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.printUrl = functions.database.ref('images/{uid}').onWrite(event => {
var request = event.data.val();
var payload = {
data:{
url : request.url,
location : request.location
}
};
admin.messaging().sendToTopic(request.topic, payload)
.then(function(response){
console.log("Successfully sent message : ", response);
})
.catch(function(error){
console.log("Error sending message : ", error);
})
});
Run Code Online (Sandbox Code Playgroud)