{"id":15043841,"url":"https://github.com/matthieulemoine/push-receiver","last_synced_at":"2025-04-12T15:33:16.790Z","repository":{"id":37580348,"uuid":"101927484","full_name":"MatthieuLemoine/push-receiver","owner":"MatthieuLemoine","description":"A library to subscribe to GCM/FCM and receive notifications within a node process.","archived":false,"fork":false,"pushed_at":"2024-08-08T15:11:24.000Z","size":156,"stargazers_count":207,"open_issues_count":38,"forks_count":82,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-03T15:08:36.315Z","etag":null,"topics":["fcm","firebase-cloud-messaging","notifications","push-notifications","webpush"],"latest_commit_sha":null,"homepage":"https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatthieuLemoine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-30T20:49:11.000Z","updated_at":"2025-01-30T17:01:47.000Z","dependencies_parsed_at":"2024-09-25T01:51:12.835Z","dependency_job_id":"d8cc7b7f-9dd3-48da-855e-89e5e08cdf9a","html_url":"https://github.com/MatthieuLemoine/push-receiver","commit_stats":{"total_commits":45,"total_committers":11,"mean_commits":4.090909090909091,"dds":0.4444444444444444,"last_synced_commit":"feb64e8342b28284a34075aa85826c8b37bac5d8"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fpush-receiver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fpush-receiver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fpush-receiver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fpush-receiver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatthieuLemoine","download_url":"https://codeload.github.com/MatthieuLemoine/push-receiver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589877,"owners_count":21129694,"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":["fcm","firebase-cloud-messaging","notifications","push-notifications","webpush"],"created_at":"2024-09-24T20:49:40.392Z","updated_at":"2025-04-12T15:33:16.761Z","avatar_url":"https://github.com/MatthieuLemoine.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# push-receiver\n\nA library to subscribe to GCM/FCM and receive notifications within a node process.\n\nFor [Electron](https://github.com/electron/electron), you can use [electron-push-receiver](https://github.com/MatthieuLemoine/electron-push-receiver) instead which provides a convenient wrapper.\n\nSee [this blog post](https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0) for more details.\n\n## When should I use `push-receiver` ?\n\n- I want to **receive** push notifications sent using Firebase Cloud Messaging in an [electron](https://github.com/electron/electron) desktop application.\n- I want to communicate with a node process/server using Firebase Cloud Messaging infrastructure.\n\n## When should I not use `push-receiver` ?\n\n- I want to **send** push notifications (use the firebase SDK instead)\n- My application is running on a FCM supported platform (Android, iOS, Web).\n\n## Install\n\n`\nnpm i -S push-receiver\n`\n\n## Requirements\n\n- Node v8 (async/await support)\n- Firebase sender id to receive notification\n- Firebase serverKey to send notification (optional)\n\n## Usage\n\n### Electron\n\nYou can use [electron-push-receiver](https://github.com/MatthieuLemoine/electron-push-receiver) instead which provides a convenient wrapper.\n\n### Node\n\n```javascript\nconst { register, listen } = require('push-receiver');\n\n// First time\n// Register to GCM and FCM\nconst credentials = await register(senderId); // You should call register only once and then store the credentials somewhere\nstoreCredentials(credentials) // Store credentials to use it later\nconst fcmToken = credentials.fcm.token; // Token to use to send notifications\nsendTokenToBackendOrWhatever(fcmToken);\n\n\n// Next times\nconst credentials = getSavedCredentials() // get your saved credentials from somewhere (file, db, etc...)\n// persistentIds is the list of notification ids received to avoid receiving all already received notifications on start.\nconst persistentIds = getPersistentIds() || [] // get all previous persistentIds from somewhere (file, db, etc...)\nawait listen({ ...credentials, persistentIds}, onNotification);\n\n// Called on new notification\nfunction onNotification({ notification, persistentId }) {\n  // Update list of persistentId in file/db/...\n  updatePersistentIds([...persistentIds, persistentId]);\n  // Do someting with the notification\n  display(notification)\n}\n```\n\n### Test notification\n\nTo test, you can use the [send script](scripts/send/index.js) provided in this repo, you need to pass your serverKey and the FCM token as arguments :\n\n```\nnode scripts/send --serverKey=\"\u003cFIREBASE_SERVER_KEY\u003e\" --token=\"\u003cFIREBASE_TOKEN\u003e\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthieulemoine%2Fpush-receiver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthieulemoine%2Fpush-receiver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthieulemoine%2Fpush-receiver/lists"}