This document describes how to prepare your development environment to use Azure IoT Edge for Node JS module development.
From a Visual Studio Developer Command Prompt:
cd <azure_iot_gateway_sdk_root>\tools\
build_nodejs.cmd
- Will download and build Node JS from source as runtime linked modules
build.cmd --enable-nodejs-binding
cd ..\samples\nodejs_simple_sample\nodejs_modules\
npm install
From the command line:
cd <azure_iot_gateway_sdk_root>/tools/
./build_nodejs.sh
- Will download and build Node JS from source as runtime linked modules
- Copy and paste the
export
message that shows up on screen to set theNODE_INCLUDE
andNODE_LIB
environment variables ./build.sh --enable-nodejs-binding
cd ../samples/nodejs_simple_sample/nodejs_modules/
npm install
In order to run a gateway with a Node.js module do the following:
cd <azure_iot_gateway_sdk_root>\samples\nodejs_simple_sample\src\
- Update
gateway_sample_win.json
by replacing<IoT Hub device connection string>
(in theiothub_writer
module config JSON (shown below)) with your actual IoT Hub device connection string
{
"name": "iothub_writer",
"loader": {
"name": "node",
"entrypoint": {
"main.path": "../../../samples/nodejs_simple_sample/nodejs_modules/iothub_writer.js"
}
},
"args": {
"connection_string": "<IoT Hub device connection string>"
}
},
cd ..\..\..\build\samples\nodejs_simple_sample\
Debug\nodejs_simple_sample ..\..\..\samples\nodejs_simple_sample\src\gateway_sample_win.json
On a terminal window follow these steps:
cd <azure_iot_gateway_sdk_root>/samples/nodejs_simple_sample/src/
- Update
gateway_sample_lin.json
by replacing<IoT Hub device connection string>
(in theiothub_writer
module config JSON (shown below)) with your actual IoT Hub device connection string
{
"name": "iothub_writer",
"loader": {
"name": "node",
"entrypoint": {
"main.path": "../../../samples/nodejs_simple_sample/nodejs_modules/iothub_writer.js"
}
},
"args": {
"connection_string": "<IoT Hub device connection string>"
}
},
cd ../../../build/samples/nodejs_simple_sample/
./nodejs_simple_sample ../../../samples/nodejs_simple_sample/src/gateway_sample_lin.json
On successful run you should see sample output like this
Gateway is running. Press return to quit.
printer.receive - 47, 33
printer.receive - 11, 12
printer.receive - 39, 30
printer.receive - 30, 21
printer.receive - 12, 0
Gateway is quitting
printer.destroy
sensor.destroy
iothub_writer.destroy