
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
English | 中文
The sample code for Node.js encapsulates the server-side APIs of Push Kit, for your reference or direct use.
The following table describes packages of Node.js sample code.
Package | Description |
---|---|
examples | Sample code packages. |
utils | Package that provides methods for sending public network requests and for common verification. |
push | Package where Push Kit server APIs are encapsulated. |
Install Node.js on your device.
Run the following command in the nodejs-sdk project:
$ npm install
Run the following command:
$ npm run build
Node.js 8.13.0 or later.
Note 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).
Start 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.
To use the functions provided by the packages in examples, set initialization and request parameters in the config.js file.
Parameter | Description |
---|---|
AppId | App ID, which is obtained from the app information. |
AppSecret | App secret, which is obtained from the app information. |
AuthUrl | URL for Huawei OAuth 2.0 to obtain a token. For details, please refer to OAuth 2.0-based Authentication. |
PushUrl | Access address of Push Kit. For details, please refer to Downlink Message Sending. |
Request Parameter | Description |
---|---|
TargetTopic | Name of the topic to be subscribed to, unsubscribed from, or queried. |
TargetCondition | Combined condition expression for sending a message. |
TargetToken | Token of a target device. |
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
You can visit the Reddit community to obtain the latest information about HMS Core and communicate with other developers.
If you have any questions about the sample code, try the following:
huawei-mobile-services
. Huawei experts will answer your questions.If you encounter any issues when using the sample code, submit your issues or submit a pull request.
The sample code is licensed under Apache License 2.0.
FAQs
HCM Node SDK.
The npm package hcm-admin receives a total of 1 weekly downloads. As such, hcm-admin popularity was classified as not popular.
We found that hcm-admin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.