Install SDK for Node.js to send and subscribe to messages through the HTTP protocol of ApsaraMQ for RocketMQ.
Prerequisites
Before you begin, make sure that you have:
Node.js 7.6.0 or later installed. To download Node.js, visit the Node.js official website
An Alibaba Cloud account with an AccessKey pair (AccessKey ID and AccessKey Secret). See Obtain an AccessKey pair
An ApsaraMQ for RocketMQ instance with a topic and a group ID. See Step 2: Create resources
The HTTP endpoint of your instance. See Obtain an HTTP endpoint
Check the Node.js version
Run the following command to verify that Node.js is installed and meets the version requirement:
node -VThe output must display version 7.6.0 or later.
Install SDK for Node.js
Run the following command to install the @aliyunmq/mq-http-sdk package:
npm i @aliyunmq/mq-http-sdkVerify the installation
Run the following command to confirm that the SDK is installed and importable:
node -e "require('@aliyunmq/mq-http-sdk'); console.log('SDK for Node.js is installed.')"If the command prints SDK for Node.js is installed. without errors, the setup is complete.
What's next
After the environment is ready, use SDK for Node.js to send and subscribe to messages: