const admin = require("firebase-admin");
const express = require('express')
const body = require('body-parser')
const path = require('path')
const fr_key = path.basename("./firebase_key.json");
const app = express();
app.use(body.json())
app.use(body.urlencoded({
extended:true
}))
// kegitannya
app.get('/',(req,res)=>{
const serviceAccount = require("./firebase_key.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://kitasehat-3f899.firebaseio.com"
});
let topic = 'berita';
let message = {
notification: {
title: 'Title of your push notification',
body: 'Body of your push notification'
},
data: {
score: '850',
time: '2:45'
},
topic: topic
};
admin.messaging().send(message).then((response) => {
// Response is a message ID string.
res.send(response)
}).catch((error) => {
res.send(error)
});
})
// Send a message to devices subscribed to the provided topic.
app.listen(1337,()=>{
console.log("app runing on port : 1337")
})
Created
June 16, 2019 03:39
-
-
Save malikkurosaki/b8796cb00b13f2df905678941fe67b95 to your computer and use it in GitHub Desktop.
push notification node js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment