UNPKG

3.13 kBMarkdownView Raw
1# Microsoft Azure IoT service SDK for Node.js
2
3The Azure IoT Service SDK for Node.js helps you build applications that interact with your devices and manage their identities in your IoT hub.
4
5[![npm version](https://badge.fury.io/js/azure-iothub.svg)](https://badge.fury.io/js/azure-iothub)
6
7## Prerequisites
8You need to install the [Node.js][nodejs_lnk] JavaScript runtime environment to run the Azure IoT JavaScript client SDK on your platform. To check if Node.js supports your platform (OS), verify that an install package is available on the [Node.js download page][nodejs_dwld_lnk].
9
10[npm][npm_lnk] is a command-line package manager that is installed with Node.js is installed, and will be used to install Azure IoT node.js client side SDK.
11
12## Installation
13
14`npm install azure-iothub` to get the latest version.
15
16## Features
17
18* Create/remove/update/list device identities in your IoT hub
19* Send messages to your devices and get feedback when they're delivered
20* Work with the Azure IoT Hub Device Twins
21* Invoke Cloud to Device Direct Methods on a device
22
23## How to use the Azure IoT service SDK for Node.js
24
25Once you have installed the package as indicated above, you can start using the features of the Service SDK in your code. Below is a code snippet showing how to add a new device in the Azure IoT Hub device registry:
26
27Note that for this sample to work, you will need to [setup your IoT hub][lnk-setup-iot-hub] and retrieve credentials for the service app. Utilize the '[IoT Connection String]', in quotes, on the command line invoking the sample.
28
29```js
30var iothub = require('azure-iothub');
31
32var connectionString = '[IoT Connection String]';
33
34var registry = iothub.Registry.fromConnectionString(connectionString);
35
36// Create a new device
37var device = {
38deviceId: 'sample-device-' + Date.now()
39};
40
41registry.create(device, function(err, deviceInfo, res) {
42 if (err) console.log(op + ' error: ' + err.toString());
43 if (res) console.log(op + ' status: ' + res.statusCode + ' ' + res.statusMessage);
44 if (deviceInfo) console.log(op + ' device info: ' + JSON.stringify(deviceInfo));
45});
46
47```
48
49Check out the [samples][samples] for details on the various features of the Service SDK
50
51## Read more
52
53* [Azure IoT Hub dev center][iot-dev-center]
54* [Azure IoT Hub documentation][iot-hub-documentation]
55* [Node.js API reference documentation][node-api-reference]
56
57
58## Directory structure
59
60Service SDK subfolders:
61
62### /devdoc
63
64Development requirements documentation
65
66### /src
67
68Code for the library
69
70### /samples
71
72Set of simple samples showing how to use the features of the Service SDK
73
74### /test
75
76Test files
77
78[nodejs_lnk]: https://nodejs.org/
79[nodejs_dwld_lnk]: https://nodejs.org/en/download/
80[npm_lnk]:https://docs.npmjs.com/getting-started/what-is-npm
81[samples]: ./samples/
82[lnk-setup-iot-hub]: https://aka.ms/howtocreateazureiothub
83[node-api-reference]: https://docs.microsoft.com/en-us/javascript/api/azure-iothub/
84[iot-dev-center]: http://azure.com/iotdev
85[iot-hub-documentation]: https://docs.microsoft.com/en-us/azure/iot-hub/