Environment requirements and configuration

Updated at:

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

  1. 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
  2. Install the Link SDK globally.

    To run a standalone script with the node <filename>.js command, you must install the Link SDK globally:

    npm install -g alibabacloud-iot-device-sdk

    Common errors after a global installation:

    • On Windows, if your script fails with an Error: Cannot find module 'alibabacloud-iot-device-sdk' error, set the NODE_PATH environment variable to the Link SDK's global installation directory.

      Note

      Ensure that NODE_PATH points 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_PATH and 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 the node command, this error is also caused by a missing NODE_PATH environment variable. Run the npm root -g command to find the npm global installation directory. Set the NODE_PATH environment variable to this directory and ensure that the change takes effect, for example, by restarting your terminal. Then, run the script with the node command 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.

    Note

    If the alibabacloud-iot-device-sdk.js file does not work in an Alipay applet after an Alipay version upgrade, use the custom version alibabacloud-iot-device-sdk-1.2.8-alimin-compatible.js. This file is located in the dist directory.

    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.js            

    Download links for the JavaScript file:

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 onProps method to handle property settings.

    • Changed the package name from aliyun-iot-device-sdk to alibabacloud-iot-device-sdk.

    • Added support for browsers and Alipay applets.

    • Added the reply function to onService with support for both synchronous and asynchronous calls.

    • Added the onConfig method 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.