# Losant MQTT Javascript Client

**URL:** <https://forums.losant.com/t/losant-mqtt-javascript-client/469>\
**Category:** Help\
**Created:** [April 26, 2017, 6:36pm UTC](https://forums.losant.com/t/losant-mqtt-javascript-client/469 "2017-04-26T18:36:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larry\_Snyder](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@Larry\_Snyder](https://forums.losant.com/u/Larry_Snyder)\
**Post date:** [April 26, 2017, 6:36pm UTC](https://forums.losant.com/t/losant-mqtt-javascript-client/469/1 "2017-04-26T18:36:02Z")

</div>

I am developing an interface between a Raspberry Pi 3B and Losant and it appears that the Losant MQTT Javascript client is the way to go.

At this point all I am trying to accomplish is to get the basic.js example running on the RPI. I copied basic.js to example.js and added my device id, key, and secret.

I am running v7.9.0 of Node.js and have the environment variable NODE\_PATH set to /usr/lib/nodejs:/home/pmmi/node\_modules/losant-mqtt/lib

When executing example.js via Node.js, I get the following error.

/home/pmmi/node\_modules/losant-mqtt/lib/device.js:57  
this.mqtt.on(‘message’, this.handleMessage.bind(this));  
^

TypeError: Cannot read property ‘bind’ of undefined  
at Device (/home/pmmi/node\_modules/losant-mqtt/lib/device.js:57:45)  
at Object. (/home/pmmi/node\_modules/losant-mqtt/examples/example.js:11:14)  
at Module.\_compile (module.js:571:32)  
at Object.Module.\_extensions…js (module.js:580:10)  
at Module.load (module.js:488:32)  
at tryModuleLoad (module.js:447:12)  
at Function.Module.\_load (module.js:439:3)  
at Module.runMain (module.js:605:10)  
at run (bootstrap\_node.js:423:7)  
at startup (bootstrap\_node.js:147:9)

Has anyone had the same problem? Any help would be very much appreciated!

---

<div class="post-metadata">

**Author:** ![Michael\_Kuehl](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/michael_kuehl/32/99_2.png) [@Michael\_Kuehl](https://forums.losant.com/u/Michael_Kuehl)\
**Post date:** [April 26, 2017, 7:33pm UTC](https://forums.losant.com/t/losant-mqtt-javascript-client/469/2 "2017-04-26T19:33:20Z")

</div>

Oh great catch! It looks like we didn’t update the example/basic.js file when we released v2 of losant-mqtt. Instead of what is currently in there:

```javascript
var device = Device({ .... });

```

you need to do create a new device instance using “new”:

```javascript
var device = new Device({ .... });

```

We will be updating the examples in the repository shortly. Thanks for pointing it out!
