Nimit Bedi Nimit Bedi - 1 year ago 92
Node.js Question

Google Cloud Messaging in Node js

What are the procedures to follow in using GCM for a node based application?
Are there specific codes required on both server side(Node js) and client side(Android/iOS)?

Answer Source
  1. Android device should sent a device token to the server to be able to receive notifications. Here an example how to do it.
  2. Get gcm key to send pushes from server.
  3. Send push with node-gcm package from npm with node.js app.

Basic example:

const gsm = require('node-gsm');
const gcmKey = ''; // Your gcm key in quotes
const deviceToken = ''; // Receiver device token
const sender = new gcm.Sender(gcmKey);

var message = new gcm.Message();

  title: 'Push',
  body: 'This is push notification',
  otherProperty: true,

sender.send(message, {registrationIds: [token]}, (err) => {
  if (err) {
  else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download