{"id":22441376,"url":"https://github.com/hms-core/hms-push-serverdemo-nodejs","last_synced_at":"2025-06-16T06:39:39.904Z","repository":{"id":112129696,"uuid":"266916923","full_name":"HMS-Core/hms-push-serverdemo-nodejs","owner":"HMS-Core","description":"Node.js sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.","archived":false,"fork":false,"pushed_at":"2023-10-23T09:32:03.000Z","size":115,"stargazers_count":29,"open_issues_count":5,"forks_count":14,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-04-16T12:54:17.411Z","etag":null,"topics":["hms","huawei","nodejs","push","push-notifications","sendmessage"],"latest_commit_sha":null,"homepage":"https://developer.huawei.com/consumer/cn/doc/development/HMS-Guides/push-introduction","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HMS-Core.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}},"created_at":"2020-05-26T01:34:45.000Z","updated_at":"2023-11-13T19:55:54.000Z","dependencies_parsed_at":"2023-10-23T10:36:09.802Z","dependency_job_id":null,"html_url":"https://github.com/HMS-Core/hms-push-serverdemo-nodejs","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/HMS-Core%2Fhms-push-serverdemo-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-push-serverdemo-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-push-serverdemo-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HMS-Core%2Fhms-push-serverdemo-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HMS-Core","download_url":"https://codeload.github.com/HMS-Core/hms-push-serverdemo-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228397819,"owners_count":17913540,"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":["hms","huawei","nodejs","push","push-notifications","sendmessage"],"created_at":"2024-12-06T02:14:19.607Z","updated_at":"2024-12-06T02:14:20.278Z","avatar_url":"https://github.com/HMS-Core.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HMS Core Push Kit Sample Code (Node.js)\nEnglish | [中文](README_ZH.md)\n## Contents\n\n * [Introduction](#Introduction)\n * [Installation](#Installation)\n * [Environment Requirements](#Environment-Requirements)\n * [Configuration](#Configuration)\n * [Sample Code](#Sample-Code)\n * [Technical Support](#technical-support)\n * [License](#License)\n\n## Introduction\n\nThe sample code for Node.js encapsulates the server-side APIs of Push Kit, for your reference or direct use.\n\nThe following table describes packages of Node.js sample code.\n| Package| Description\n| ---- | ----- \n| [examples](examples) | Sample code packages.\n| [utils](src/utils) | Package that provides methods for sending public network requests and for common verification.\n| [push](src/push) | Package where Push Kit server APIs are encapsulated.\n\n## Installation\n\nInstall Node.js on your device.\n\nRun the following command in the **nodejs-sdk** project:\n\n```bash\n$ npm install\n```\n\nRun the following command:\n\n```bash\n$ npm run build\n```\n\n## Environment Requirements\n\nNode.js 8.13.0 or later.\n\nNote that the Node.js sample code can be used only in the server-side or background environments that you control, including most servers and serverless platforms (both on-premise and in the cloud).\n\n## Configuration\n\nStart configuration with the **index.ts** file. Create an **HcmNamespace** object, and call the methods in the object to perform initialization. Access different modules, such as the messaging or topic module, and call the methods in each module.\n\nTo use the functions provided by the packages in **examples**, set initialization and request parameters in the **config.js** file.\n\n\n| Parameter| Description|\n| ---- | ----- |\n| AppId|App ID, which is obtained from the app information.|\n| AppSecret|App secret, which is obtained from the app information.|\n| AuthUrl|URL for Huawei OAuth 2.0 to obtain a token. For details, please refer to [OAuth 2.0-based Authentication](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/oauth2-0000001212610981).|\n| PushUrl|Access address of Push Kit. For details, please refer to [Downlink Message Sending](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-server-dev-0000001050040110?ha_source=hms1).|\n\n\n| Request Parameter| Description|\n| ---- | ----- |\n| TargetTopic|Name of the topic to be subscribed to, unsubscribed from, or queried.|\n| TargetCondition|Combined condition expression for sending a message.|\n| TargetToken|Token of a target device.|\n\n\n## Sample Code\n\nnode.js sample code uses index.ts as the entry. Call methods on object HcmNamespace: messaging and topic.\n\nThe following table lists methods in HcmNamespace.\n| Method | Description |\n| ---- | ---- |\n| messaging | The entry of the Messaging object, and verify the initialization input parameters. |\n| topic | The entry of the Topic object, and verify the initialization input parameters. |\n\t\nThe following table lists methods in Messaging.\n| Method | Description |\n| ---- | ---- |\n| send | Verify if the token needs to be updated and call the method sendRequest. |\n| sendRequest | Sends a message to a device. |\n\nThe following table lists methods in Topic.\n| Method | Description |\n| ---- | ---- |\n| subScribeTopic | Subscribe to topic. |\n| unSubScribeTopic | Unsubscribe topic. |\n| queryTopicList | Query subject list. |\n\n#### 1. Send an Android data message.\nCode location: [examples/send_data_message.js](examples/send_data_message.js)\n\n#### 2. Send an Android notification message.\nCode location: [examples/send_notify_message.js](examples/send_notify_message.js)\n\n#### 3. Send a message by topic.\nCode location: [examples/send_topic_message.js](examples/send_topic_message.js)\n\t\n#### 4. Send a message by conditions.\nCode location: [examples/send_condition_message.js](examples/send_condition_message.js)\n\n#### 5. Send a message to a Huawei quick app.\nCode location: [examples/send_instance_app_message.js](examples/send_instance_app_message.js)\n\n#### 6. Send a message through the WebPush agent.\nCode location: [examples/send_webpush_message.js](examples/send_webpush_message.js)\n\n#### 7. Send a message through the APNs agent.\nCode location: [examples/send_apns_message.js](examples/send_apns_message.js)\n\n#### 8. Send a test message.\nCode location: [examples/send_test_message.js](examples/send_test_message.js)\n\n## Technical Support\nYou can visit the [Reddit community](https://www.reddit.com/r/HuaweiDevelopers/) to obtain the latest information about HMS Core and communicate with other developers.\n\nIf you have any questions about the sample code, try the following:\n- Visit [Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Votes), submit your questions, and tag them with `huawei-mobile-services`. Huawei experts will answer your questions.\n- Visit the HMS Core section in the [HUAWEI Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001?ha_source=hms1) and communicate with other developers.\n\nIf you encounter any issues when using the sample code, submit your [issues](https://github.com/HMS-Core/hms-push-serverdemo-nodejs/issues) or submit a [pull request](https://github.com/HMS-Core/hms-push-serverdemo-nodejs/pulls).\n\n## License\nThe sample code is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhms-core%2Fhms-push-serverdemo-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhms-core%2Fhms-push-serverdemo-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhms-core%2Fhms-push-serverdemo-nodejs/lists"}