So i'm making an app using React JS, Cordova, node backend and a mongo database. I want to integrate firebase cloud messaging (FCM) into my platform. I'm quite new to firebase, and developing in general, and i'm not quite sure where to initialise firebase. I currently have it integrated into the front-end and it's requesting permission to receive notifications, generating tokens, and receiving messages from the firebase console. However i'm not entirely sure where to go from here. Do I add it to my backend as-well?
Asked
Active
Viewed 705 times
2 Answers
1
- You have to get the
FCM token
from the frontend (or, client app). - After getting the token, just send it to your backend server using a
POST
method. - Then,
store the token
in whatever database you're using in your backend. It can be MongoDB, PostgreSQL, etc.

Shariful Islam Mubin
- 2,146
- 14
- 23
1
If you can receive messages in your client app, your front-end work is done for the moment.
But to send messages programmatically, you will need to write back-end code indeed. That's because sending messages through FCM requires that you specify the FCM server key to the API, and as its name implies that key should only be used in a trusted environment, such as your development machine, a server you control, or Cloud Functions.
For more on this, have a look at:
- The architectural overview of FCM
- The documentation on your server and FCM
- My answer to How to send one to one message using Firebase Messaging

Frank van Puffelen
- 565,676
- 79
- 828
- 807
-
Thank you very much for the reply I'll be sure to checkout the docs and your solution – EthanNeedsHelpCoding Aug 13 '21 at 13:03