English | 中文
Node.js sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.
The following table describes packages of Node.js sample code.
Package | Description |
---|---|
examples | Sample code packages. Each package can run independently to call an API. |
utils | Tool package, which contains common network requests and common verification methods. |
push | Package where APIs of the HUAWEI Push Kit server are encapsulated. |
Before using Node.js sample code, ensure that the node environment has been installed.
In the nodejs-sdk project directory:
$ npm install
Run the sample project:
$ npm run build
We support Node.js 8.13.0 and higher.
Please also note that the Sample Code should only be used in server-side/back-end environments controlled by the app developer. This includes most server and serverless platforms (both on-premise and in the cloud). It is not recommended to use the Sample Code in client-side environments.
Node.js sample code uses the index.ts file as the entry, creates a HcmNamespace object, calls a method in the object for initialization, enters a method module such as the message or topic method module, and then calls an API of the HUAWEI Push Kit server using a method in the module.
Before using functions provided by packages in examples, you need to set parameters for initialization in config.js.
Initialization Parameter | Description |
---|---|
AppId | App ID, which is obtained from app information. |
AppSecret | Secret access key of an app, which is obtained from app information. |
AuthUrl | URL for the Huawei OAuth 2.0 service to obtain a token, please refer to Generating an App-Level Access Token. |
PushUrl | URL for accessing HUAWEI Push Kit, please refer to Sending Messages. |
Request Parameter | Description |
---|---|
TargetTopic | Name of a topic to be subscribed to, unsubscribed from, or queried. |
TargetCondition | Combination of condition expressions for a message. |
TargetToken | Token of a destination device. |
TargetTokenArray | Tokens of destination devices. |
node.js sample code uses index.ts as the entry. Call methods on object HcmNamespace: messaging and topic.
The following table lists methods in HcmNamespace.
Method | Description |
---|---|
messaging | The entry of the Messaging object, and verify the initialization input parameters. |
topic | The entry of the Topic object, and verify the initialization input parameters. |
The following table lists methods in Messaging.
Method | Description |
---|---|
send | Verify if the token needs to be updated and call the method sendRequest. |
sendRequest | Sends a message to a device. |
The following table lists methods in Topic.
Method | Description |
---|---|
subScribeTopic | Subscribe to topic. |
unSubScribeTopic | Unsubscribe topic. |
queryTopicList | Query subject list. |
Code location: examples/send_data_message.js
Code location: examples/send_notify_message.js
Code location: examples/send_topic_message.js
Code location: examples/send_condition_message.js
Code location: examples/send_instance_app_message.js
Code location: examples/send_webpush_message.js
Code location: examples/send_apns_message.js
Code location: examples/send_test_message.js
If you want to evaluate more about HMS Core, r/HMSCore on Reddit is for you to keep up with latest news about HMS Core, and to exchange insights with other developers.
If you have questions about how to use HMS samples, try the following options:
huawei-mobile-services
.If you run into a bug in our samples, please submit an issue to the Repository. Even better you can submit a Pull Request with a fix.
Pushkit Node.js sample is licensed under the Apache License, version 2.0.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
Activity
Community
Health
Trend
Influence
:Code submit frequency
:React/respond to issue & PR etc.
:Well-balanced team members and collaboration
:Recent popularity of project
:Star counts, download counts etc.