node.js - Node and Firebase Cloud Messaging TypeError -
keep receiving typeerror , cant figure out why. installed firebase using (npm install firebase --save
). here code:
var firebase = require("firebase"); // firebase var express = require('express'); // express instaniated different way serving static webpages var app = express(); // express app include // set port app.listen(8085); // initialize firebase var config = { apikey: "aiza...............", authdomain: ".....firebaseapp.com", databaseurl: "...............", storagebucket: "..........appspot.com", messagingsenderid: "..............." }; firebase.initializeapp(config); // create url using firebase app.get('/fcmtest', function (req, res) { const messaging = firebase.messaging(); messaging.requestpermission() .then(function () { console.log("have permission") }) .catch(function (err) { console.log("do not have permission"); }); });
this error receiving. initializeapp seems working fine messaging not working. (npm -v firebase) spits out 3.10 npm webpage says latest 3.6.1.
typeerror: firebase.messaging not function @ /usr/gserv/services/app.js:226:32 @ layer.handle [as handle_request] (/usr/gserv/services/node_modules/express/lib/router/layer.js:95:5) @ next (/usr/gserv/services/node_modules/express/lib/router/route.js:131:13) @ route.dispatch (/usr/gserv/services/node_modules/express/lib/router/route.js:112:3) @ layer.handle [as handle_request] (/usr/gserv/services/node_modules/express/lib/router/layer.js:95:5) @ /usr/gserv/services/node_modules/express/lib/router/index.js:277:22 @ function.process_params (/usr/gserv/services/node_modules/express/lib/router/index.js:330:12) @ next (/usr/gserv/services/node_modules/express/lib/router/index.js:271:10) @ /usr/gserv/services/node_modules/connect-busboy/index.js:14:14 @ layer.handle [as handle_request] (/usr/gserv/services/node_modules/express/lib/router/layer.js:95:5)
any appreciated.
after reading this: https://www.npmjs.com/package/firebase
"firebase cloud messaging not included in server side firebase npm module. instead, can use firebase cloud messaging rest api."
so should make rest calls messaging, cannot use messaging function in code tried.
see rest api documentation: https://firebase.google.com/docs/cloud-messaging/send-message#http_post_request
Comments
Post a Comment