Vytvořit projekt:
npm init npm install firebase-admin
Přidat JSON z google do souboru serviceAccountKey.json
Vytvořit index.js:
var admin = require("firebase-admin"); var serviceAccount = require("./serviceAccountKey.json"); const registrationToken = 'dmcppyoGS6Csjt0-3COKVC:APA91bFWpKXYENNMXxUfap3Hp5X3L0sHVG0W6apzvdJwubki_JMfbi0a2En0JpusLPunser8EWOXTaBMF6tBE83yk2tkJvekEK0ycyyjxE4O-DMmiSl1ko6VltZrhJpYmbkuOZxcVIwq'; admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "https://jnfdjvnojnf.firebaseio.com" }); const payload = { notification : { title : "IS IS COOL !", body : "Notification has been recieved", } } const options = { priority: "high" } admin.messaging().sendToDevice(registrationToken, payload, options) .then(function (response) { console.log("ok", response); console.log("ok", JSON.stringify(response)); }) .catch(function (error) { console.log("error", error); });
A spustit:
node index.js