Olivia Delpierre
Olivia Delpierre

Reputation: 107

Why use MQTT Node.JS library?

I am currently building a web app using the Paho MQTT Javascript library, and I was wondering in what case should I use the MQTT.JS library ? Could you give me examples when I cannot use the Javascript library and need to use the MQTT.js library (which I think is made for Node.js) ?

(I know the two things are completely different but still, they both concern web applications!)

Thank you !

Upvotes: 5

Views: 3082

Answers (2)

hardillb
hardillb

Reputation: 59618

The Paho JavaScript client is specifically targeted for use in client side (in the browser) and uses MQTT over Websockets to connect to MQTT brokers that support this transport layer. It is the reference implementation for MQTT over Websockets.

Assuming you mean the MQTT.js package when talking about the "Node.JS one" this is a pure javascript implementation of the a MQTT client that can use either native MQTT or MQTT over Websockets when used with Node.JS to build client applications. It can also be used with a tool such as Browserify and Webpack then it can be packaged to be used in the web browser to connect to a MQTT broker using MQTT over Websockets

When you choose to use each depends on what you are trying to do, if you are purely writing a web client solution then the Paho library will meet your needs. If you are writing a Node.JS application then obviously then the MQTT.js is the correct choice. If you are writing both then there may be some merit in using the MQTT.js library in the both places to ensure consistency.

Upvotes: 6

raj peer
raj peer

Reputation: 718

when you use mqtt broker, you should install npm package of mqtt, that package you can get from node.js.

using command : npm install mqtt

Upvotes: -3

Related Questions