I have made a script for sending push notifications to my Firebase server, but javascript eslint is throwing error for const first.
Then I found on Google that I have to put ecmaVersion = 6 in my .eslintsrc file. I did that then it is showing error on require, exports and console field.
I am using Atom as my compiler for code. This is my code:
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);
})
});
You need to let eslint know that you're working in a Node environment to get rid of the require and exports errors. So by adding this to your eslintConfig:
"env": {
"node": true
}
In order to allow the console.log, you will have to turn on the rule by adding this to your eslintconfig:
"rules": {
"no-console": 0
}
You can find more information here: https://eslint.org/docs/user-guide/configuring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With