https://github.com/sohelamin/push-notification
Push Notification
https://github.com/sohelamin/push-notification
notification push-notifications service-worker
Last synced: 6 months ago
JSON representation
Push Notification
- Host: GitHub
- URL: https://github.com/sohelamin/push-notification
- Owner: sohelamin
- Created: 2018-06-27T20:06:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T06:18:04.000Z (almost 3 years ago)
- Last Synced: 2025-04-02T15:11:10.411Z (6 months ago)
- Topics: notification, push-notifications, service-worker
- Language: JavaScript
- Homepage:
- Size: 57.6 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Push Notification
> Push Notification Implementation Using Service Worker & Web Push Protocol## Pre-requisites
- HTTPS enabled site
- [Service Worker](https://developers.google.com/web/fundamentals/primers/service-workers/) (Client)
- [Web Push](https://github.com/web-push-libs/web-push) (Server)## Installation
```
npm install
```## Usage
1. Run the Web Push server
```
node app.js
```2. Serve the client app with any http server
```
cd client
python -m SimpleHTTPServer 8888
```
3. Visit the client app and allow notification
4. Send notification to the subscribed users
Simple notification
```bash
curl -XPOST -H 'Content-Type: application/json' http://localhost:3000/send -d '
{
"notification": {
"title": "Push Notification",
"body": "Hey Dude!",
"icon": "icon.png",
"url": "https://www.appzcoder.com/"
}
}
'
```
You will get the notification like this
Notification with action buttons
```bash
curl -XPOST -H 'Content-Type: application/json' http://localhost:3000/send -d '
{
"notification": {
"title": "Push Notification",
"body": "Hey Dude!",
"icon": "icon.png",
"actions": [
{ "action": "ok", "title": "Ok", "url": "https://www.appzcoder.com/" },
{ "action": "cancel", "title": "Cancel", "url": "https://google.com/" }
]
}
}
'
```