# Losant JavaScript MQTT Client in the Browser?

**URL:** <https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305>\
**Category:** Help\
**Created:** [December 16, 2016, 3:39pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305 "2016-12-16T15:39:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Voronin](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Greg\_Voronin](https://forums.losant.com/u/Greg_Voronin)\
**Post date:** [December 16, 2016, 3:39pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/1 "2016-12-16T15:39:02Z")

</div>

Can I use losant-mqtt,js in my browser? Can I import it as use it as part of the JavaScript on a webpage?

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [December 16, 2016, 3:49pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/2 "2016-12-16T15:49:47Z")

</div>

I haven’t confirmed it myself, but losant-mqtt is a wrapper around MQTT.js, which is supported in the browser: [https://github.com/mqttjs/MQTT.js#browser](https://github.com/mqttjs/MQTT.js#browser)

So with something like Webpack or Browserify, you should be able to use losant-mqtt in the browser. Give it a try and let us know!

---

<div class="post-metadata">

**Author:** ![Greg\_Voronin](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Greg\_Voronin](https://forums.losant.com/u/Greg_Voronin)\
**Post date:** [December 16, 2016, 4:09pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/3 "2016-12-16T16:09:48Z")

</div>

Brandon,

Thanks! will do. If I can get it to work,

Greg

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [December 16, 2016, 4:12pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/4 "2016-12-16T16:12:40Z")

</div>

Worst-case scenario, our [underlying mqtt protocol](https://docs.losant.com/mqtt/overview/) is pretty straightforward, so you could use MQTT.js directly in the browser.

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [December 16, 2016, 4:46pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/5 "2016-12-16T16:46:07Z")

</div>

Greg, I just confirmed that it works.

Check out this gist: [https://gist.github.com/anaptfox/708cd010a53d19b7b7dc029a235ca092](https://gist.github.com/anaptfox/708cd010a53d19b7b7dc029a235ca092)

The key is to set the transport to web sockets. I did that here:

> <https://gist.github.com/anaptfox/708cd010a53d19b7b7dc029a235ca092#file-losant-mqtt-browser-js-L13>

Just add `transport: 'ws'` to the Device options.

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [December 16, 2016, 4:47pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/6 "2016-12-16T16:47:49Z")

</div>

You can also test things out pretty quickly with: [RequireBin.com](http://RequireBin.com)

---

<div class="post-metadata">

**Author:** ![Greg\_Voronin](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Greg\_Voronin](https://forums.losant.com/u/Greg_Voronin)\
**Post date:** [December 16, 2016, 5:36pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/7 "2016-12-16T17:36:34Z")

</div>

Brandon,

Thanks! I had some thoughts along the same line, just not sure how to use the Losant without the wrapper. A bit new to this IoT and MQTT game. Amazingly I had the weather station example up connected to a slack channel AND my edison sending data to Losant in a matter of a couple of hours. Losant is pretty amazing.

Greg

---

<div class="post-metadata">

**Author:** ![Greg\_Voronin](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Greg\_Voronin](https://forums.losant.com/u/Greg_Voronin)\
**Post date:** [December 16, 2016, 5:37pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/8 "2016-12-16T17:37:08Z")

</div>

anaptfox,

Thanks! Will try as soon as I can!

Greg

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [December 16, 2016, 5:37pm UTC](https://forums.losant.com/t/losant-javascript-mqtt-client-in-the-browser/305/9 "2016-12-16T17:37:50Z")

</div>

No Problem! Please reach out if you have more questions.
