Registry / messaging / fcm-rest-api

fcm-rest-api

JSON →
library1.0.7jsnpmunverified

A Node.js library for Firebase Cloud Messaging (FCM) using REST APIs. Supports sending push notifications to Android, iOS, Web, and topics, as well as subscribing/unsubscribing devices to topics. Uses service account private key for authentication. Current version 1.0.7 has limited recent updates (last update in 2020). Simpler alternative to @firebase/messaging, but lacks TypeScript types and advanced features like message targeting conditions.

npm install fcm-rest-api
INSTALL
IMPORT
SIG · FCM-REST-API
F
fcm-rest-api
messagingjavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fcm-rest-api default
const fcm = require('fcm-rest-api')
import fcm from 'fcm-rest-api'
Library does not export ESM; use CommonJS require. No default exports.
fcm.sendPushToTokens
fcm.sendPushToTokens(serverKey, tokens, notificationObj, additionalObj, platform)
fcm.sendPushToTokens(serverKey, tokens, notificationObj, additionalObj)
The platform argument is required (e.g., 'android'). Omission may cause error.
fcm.subscribeToTopic
fcm.subscribeToTopic(serverKey, tokens, topic)
Tokens must be an array of strings.
fcm.unSubscribeToTopic
fcm.unSubscribeToTopic(serverKey, tokens, topic)
Function name is case-sensitive: 'unSubscribeToTopic' not 'unsubscribeToTopic'.

Sends a push notification to Android devices using FCM REST API with a service account private key.

const fcm = require('fcm-rest-api'); const serverKey = require('./path/to/privatekey.json'); const tokens = ['device_token_1', 'device_token_2']; const notificationObj = { title: 'Hello', body: 'World', click_action: 'https://example.com', image: 'https://example.com/image.png', badge: '1' }; const additionalObj = { key1: 'value1', key2: 'value2' }; fcm.sendPushToTokens(serverKey, tokens, notificationObj, additionalObj, 'android') .then(response => console.log(response)) .catch(err => console.error(err));
Debug
Known issues
gotchaPlatform argument is case-sensitive. Must be exactly 'android', 'ios', or 'web'.
fix
Ensure platform string is lowercased: 'android', 'ios', 'web'.
affects: *
gotchaThe 'tokens' parameter must be an array even for a single token. Passing a string will cause an error.
fix
Wrap single token in array: ['token'].
affects: *
deprecatedThe library uses node-fetch v2, which is deprecated. May have compatibility issues with newer Node.js versions.
fix
Use an alternative library like firebase-admin or @google-cloud/firestore for up-to-date FCM support.
affects: >=1.0.7
gotchaFunction 'unSubscribeToTopic' has capital 'S' and 'T'. Incorrect casing leads to undefined function error.
fix
Use 'fcm.unSubscribeToTopic' exactly as shown.
affects: *
gotchaPrivate key file must be a JSON object (service account key), not a string. A string will cause authentication failure.
fix
Use require('./path/to/key.json') to load the key object.
affects: *
Errors
Common errors & fixes
TypeError: fcm.sendPushToTokens is not a function
Incorrect import: using ES module import 'import fcm from 'fcm-rest-api'' instead of CommonJS require.
fix
Replace import with: const fcm = require('fcm-rest-api');
Error: Invalid platform. Must be one of android, ios, web.
Platform argument missing or misspelled (e.g., 'Android' with capital A).
fix
Pass 'android', 'ios', or 'web' (lowercase) as the 5th argument.
Error: tokens is not iterable
Tokens parameter is not an array (e.g., a single string).
fix
Ensure tokens is an array: ['single_token'].
Error: ENOENT: no such file or directory, open '...'
Invalid path to private key JSON file.
fix
Provide correct path to the Firebase service account key JSON file.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
node-fetchrequiredHTTP client for FCM REST API calls
Agent activity
12 hits · last 30 days
node
10
Bingbot
1
OpenAI (training)
1
Resources
fcm-rest-api — npm install fcm-rest-api · libregistry