Environment requirements and configuration
This topic describes how to configure and use the Link SDK in a Node.js environment.
Prerequisites
Requires Node.js version 4.0.0 or later.
Install the Link SDK using npm
-
Install the Link SDK into your project directory.
This method is recommended when you want to integrate the Alibaba Cloud Link SDK into an existing Node.js project:
npm install alibabacloud-iot-device-sdk --save -
Install the Link SDK globally.
To run a standalone script with the
node <filename>.jscommand, you must install the Link SDK globally:npm install -g alibabacloud-iot-device-sdkCommon errors after a global installation:
-
On Windows, if your script fails with an
Error: Cannot find module 'alibabacloud-iot-device-sdk'error, set theNODE_PATHenvironment variable to the Link SDK's global installation directory.NoteEnsure that
NODE_PATHpoints to the Link SDK installation directory.In Windows, open the Environment Variables dialog box. In the System variables section, click New. Set Variable name to
NODE_PATHand Variable value to the path of the Link SDK's global node_modules directory (for example,C:\Users\{username}\AppData\Roaming\npm\node_modules). Then, click OK. -
On Linux, if you receive an
Error: Cannot find module 'alibabacloud-iot-device-sdk'error when running a script with thenodecommand, this error is also caused by a missingNODE_PATHenvironment variable. Run thenpm root -gcommand to find the npm global installation directory. Set theNODE_PATHenvironment variable to this directory and ensure that the change takes effect, for example, by restarting your terminal. Then, run the script with thenodecommand again.
-
Source code
The Node.js Link SDK is open source. For more information, see alibabacloud-iot-device-sdk.
Referencing the Link SDK
-
Reference the Link SDK in a Node.js program.
To use the SDK's APIs, add it as a dependency in your code:
const iot = require('alibabacloud-iot-device-sdk'); -
Integrate the Link SDK in other environments such as browsers or Alipay applets.
NoteIf the
alibabacloud-iot-device-sdk.jsfile does not work in an Alipay applet after an Alipay version upgrade, use the custom versionalibabacloud-iot-device-sdk-1.2.8-alimin-compatible.js. This file is located in thedistdirectory.const iot = require('./dist/alibabacloud-iot-device-sdk.js'); // Use the actual SDK path. // For Alipay applets, use ./dist/alibabacloud-iot-device-sdk-1.2.8-alimin-compatible.jsDownload links for the JavaScript file:
-
GitHub download: GitHub Download
-
CDN download:
-
Release notes
This section lists the major changes in each version.
-
1.2.8
Fixed an issue that caused the SDK to be incompatible with Alipay applets after an Alipay version upgrade.
-
1.2.7
-
Redefined the parameters for event and property reporting.
-
Added the
onPropsmethod to handle property settings. -
Changed the package name from
aliyun-iot-device-sdktoalibabacloud-iot-device-sdk. -
Added support for browsers and Alipay applets.
-
Added the
replyfunction toonServicewith support for both synchronous and asynchronous calls. -
Added the
onConfigmethod to subscribe to remote configuration updates from the cloud. -
Added examples for several features.
-
Rewrote the implementation for gateway sub-devices.
-
-
1.0.1
-
Added device tag reporting.
-
Added device tag deletion.
-
Added support for dynamic device registration.
-
Added device shadow features.
-
Added device configuration retrieval.
-