node.js & js

node js Fcm 설치

Machine_웅 2019. 5. 14. 15:04
728x90
반응형

Warning: on February 2, 2017, the Firebase Team released the admin.messaging() service to their node.js admin module. This new service makes this module kind of deprecated

fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages, and parallel calls.
Aditionally it also keeps the callback behavior for the new firebase messaging service.

Installation

Via npm:

$ npm install fcm-node

Usage

There are 2 ways to use this lib:

The classic one

  1. Generate a Server Key on your app's firebase console and pass it to the FCM constructor
  2. Create a message object and call the send() function

Classic usage example:

var FCM = require('fcm-node');

var serverKey = 'YOURSERVERKEYHERE'; //put your server key here

var fcm = new FCM(serverKey);

 

var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)

to: 'registration_token',

collapse_key: 'your_collapse_key',

 

notification: {

title: 'Title of your push notification',

body: 'Body of your push notification'

},

 

data: { //you can send only notification or only data(or include both)

my_key: 'my value',

my_another_key: 'my another value'

}

};

 

 

출처 :  https://www.npmjs.com/package/fcm-node

728x90
반응형