{"id":17816668,"url":"https://github.com/saurabhdaware/pwainit-node-pushapi","last_synced_at":"2025-08-05T09:20:38.227Z","repository":{"id":42992170,"uuid":"201444031","full_name":"saurabhdaware/pwainit-node-pushapi","owner":"saurabhdaware","description":"Push API backend code along with the instructions to generate and use VAPID keys.","archived":false,"fork":false,"pushed_at":"2022-12-11T01:23:25.000Z","size":31,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-13T06:44:57.757Z","etag":null,"topics":["node-pushapi","progressive-web-app","push-notifications","pushapi","pwa","pwainit","pwainit-backend"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saurabhdaware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-09T10:14:08.000Z","updated_at":"2023-03-04T10:19:51.000Z","dependencies_parsed_at":"2023-01-26T12:31:39.012Z","dependency_job_id":null,"html_url":"https://github.com/saurabhdaware/pwainit-node-pushapi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fpwainit-node-pushapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fpwainit-node-pushapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fpwainit-node-pushapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fpwainit-node-pushapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saurabhdaware","download_url":"https://codeload.github.com/saurabhdaware/pwainit-node-pushapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221705527,"owners_count":16866985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node-pushapi","progressive-web-app","push-notifications","pushapi","pwa","pwainit","pwainit-backend"],"created_at":"2024-10-27T16:38:56.227Z","updated_at":"2024-10-27T16:38:56.682Z","avatar_url":"https://github.com/saurabhdaware.png","language":"JavaScript","readme":"# NodeJS PushAPI Example\n\n## Local Installation and Generating Vapid Keys\n- `git clone https://github.com/saurabhdaware/pwainit-node-pushapi`\n- `cd pwainit-node-pushapi`\n- `npm install`\n- `./node_modules/.bin/web-push generate-vapid-keys`\n- Create a .env file in root directory and copy paste following content and replace above generated keys with the values below \n```\nPUBLIC_VAPID_KEY = \"\u003cYour public vapid key\u003e\"\nPRIVATE_VAPID_KEY = \"\u003cYour private vapid key\u003e\"\nEMAIL = \"\u003cYour email address\u003e\"\n```\n- `node index.js`\n\n## Client side setup\n**Checkout [pwainit](https://github.com/saurabhdaware/pwainit) to initate the client side part in one command**\n\n- You will have to use generated public vapid key on client side to generate subscription.\n- If you have used [PWAinit](https://github.com/saurabhdaware/pwainit) to generate PWA you will have to Paste the key in `publicVapidKey` variable in index.html script tag.\n- Go through the [Push API docs](https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications) to understand the code properly.\n- Make sure you have following code in your service worker file.\n\n### sw.js\n```js\n// NOTIFICATIONS\n// Please go through https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications#push_api to understand this properly\n\n// Listens to push events from server.\nself.addEventListener('push', function(e) {\n    const dataFromServer = e.data.json(); // or your can add e.data.text() and pass text data from server\n\n    var options = {\n            body: dataFromServer.body,\n            icon: 'assets/logo-512.png',\n            vibrate: [100, 50, 100],\n            data: {\n                dateOfArrival: Date.now(),\n                // primaryKey: '2'\n            },\n            actions:[\n                {action: 'github', title: 'Open Github Repo', icon: 'images/checkmark.png'},\n                {action: 'close', title: 'Close notification', icon: 'images/xmark.png'},\n            ]\n    };\n    e.waitUntil(\n        self.registration.showNotification(dataFromServer.title, options)\n    );\n});\n\nself.addEventListener('notificationclick', function(e) {\n    var notification = e.notification;\n    var primaryKey = notification.data.primaryKey;\n    var action = e.action;\n\n    if (action === 'close') {\n        notification.close();\n    }else if(action == 'github'){\n        clients.openWindow('https://github.com/saurabhdaware/pwainit')\n        notification.close();\n    }else {\n        console.log('..')\n        notification.close();\n    }\n});`\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaurabhdaware%2Fpwainit-node-pushapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaurabhdaware%2Fpwainit-node-pushapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaurabhdaware%2Fpwainit-node-pushapi/lists"}