expresso
  • Get Started
    • 👋Welcome!
    • ⚡Quick Start
  • Expresso Library
    • 📖Introduction
    • ⚛️expresso-core
      • Currency
      • Random String
      • Formatter
      • File
      • Phone
    • ⚓expresso-hooks
      • Multer
      • Token
      • OTP
    • 🚀expresso-provider
      • FCM
      • SMTP
      • Redis
      • Storage
    • 🔗expresso-query
      • TypeORM
      • Sequelize
Powered by GitBook
On this page
  • Initialize FCM
  • FCM Send To Device
  1. Expresso Library
  2. expresso-provider

FCM

Firebase Cloud Messaging

Previousexpresso-providerNextSMTP

Last updated 1 year ago

FCM Provider from expresso-provider

Using commonjs

const { FCM } = require('expresso-provider')

Using ES6

import { FCM } from 'expresso-provider'

Initialize FCM

// config/fcm.ts

import { FCM } from 'expresso-provider'
import * as admin from 'firebase-admin'
import path from 'path'

const serviceAccountPath = path.resolve(
  `${process.cwd()}/public/gcp/fcm_serviceAccount.json`
)

export const fcmService = new FCM({
  options: { credential: admin.credential.cert(serviceAccountPath) },
})

fcmService.initialize()

FCM Send To Device

import { fcmService } from 'config/fcm'

const payload = {
    'text': 'any value'
}

const dataFcm = await fcmService.sendToDevice({
    appName: 'My App',
    title: 'Your App Notif',
    deviceTokens: ['device_token_1', 'device_token_2'],
    message: 'Welcome to my App',
    type: 'Notif',
    data: JSON.stringify(payload),
})

console.log({ dataFcm })
🚀
npm: firebase-adminnpm
firebase admin to provider FCM
Logo