AWS IoT and Node.js on the Raspberry Pi

DZone 's Guide to

AWS IoT and Node.js on the Raspberry Pi

Having a hard time getting Node.js working with AWS IoT? Running into ES6 class syntax problems? Here's how to solve them.

· IoT Zone ·
Free Resource

There are many approaches for installing Node.js on a Raspberry Pi (Google and you’ll find lots of guides), presumably because, for a while, there didn’t seem to be any official binaries in the official apt repos, so people were building and sharing their own.

I installed a version from somewhere (can’t actually remember where, as it was a while back) and it doesn’t support ES6 class syntax used by some of the dependent libraries in the AWS IoT SDK:

$ node index.js
class Server extends WebSocketServer{
SyntaxError: Unexpected reserved word
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/pi/aws-iot-nodejs-pi-lights/node_modules/aws-iot-device-sdk/node_modules/mqtt/node_modules/websocket-stream/index.js:2:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

The version I currently have installed is:

pi@raspberrypi:~ $ node -v

Since I’m not sure where this version came from originally, (and apt-get upgrade is not finding any updates), I uninstalled:

sudo apt-get remove nodejs
sudo apt-get remove npm

Then I followed the steps in the AWS IoT SDK guide here to install using the version provided from Adafruit’s repo (official Node.js binaries for ARM are also available from nodejs.org here).

With the version provided from Adafruit, this gives me v0.12.6 but unfortunately, this still gives the same error with the ES6 class keyword.

$ node -v

Next, let's try the ARM version from nodejs.org. There’s step by step instructions showing how to download the TAR and extract and copy to /usr/local/

Now we have:

$ node -v

And now trying to run my AWS IoT Node.js-based app is a success!

aws iot ,iot ,node.js ,raspberry pi ,tutorial

Published at DZone with permission of Kevin Hooke , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}