mqtt
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
base64-js | 1.5.1 | 4.01 kB | MIT | prod | |
commist | 1.1.0 | 3.24 kB | MIT | prod | |
concat-stream | 1.6.2 | 3.72 kB | MIT | prod | |
duplexify | 4.1.3 | 17.87 kB | MIT | prod | |
end-of-stream | 1.4.4 | 2.33 kB | MIT | prod | |
es6-map | 0.1.5 | 7.77 kB | MIT | prod | 1 |
help-me | 1.1.0 | 3.74 kB | MIT | prod | 1 |
inherits | 2.0.4 | 1.98 kB | ISC | prod | |
minimist | 1.2.8 | 15.16 kB | MIT | prod | |
mqtt-packet | 6.10.0 | 27.45 kB | MIT | prod | |
pump | 3.0.0 | 3.16 kB | MIT | prod | |
readable-stream | 2.3.8 | 25.14 kB | MIT | prod | |
reinterval | 1.1.0 | 3.15 kB | MIT | prod | |
split2 | 3.2.2 | 4.58 kB | ISC | prod | |
websocket-stream | 5.5.2 | 8.01 kB | BSD-2-Clause | prod | |
xtend | 4.0.2 | 2.47 kB | MIT | prod |
MQTT.js is a client library specifically designed for the MQTT protocol. Written in JavaScript, it's ideal for Node.js and browser environments. MQTT (Message Queuing Telemetry Transport) is a lightweight, publish-subscribe messaging protocol usually used for machine-to-machine (M2M) or Internet of Things applications where bandwidth and resource constraints often exist.
To use MQTT.js, you must first install the package using npm with the following command: npm install mqtt --save
. Once installed, you can require it in your JavaScript file and use its functions to connect to a broker and publish or subscribe to topics. To give an example, the below code connects to a broker and publishes a message:
const mqtt = require("mqtt");
const client = mqtt.connect("mqtt://broker-url");
client.on("connect", () => {
client.publish("topic-name", "Hello mqtt");
client.end();
});
In this example, replace "mqtt://broker-url" with the URL of your MQTT broker, and "topic-name" with the name of your topic. The message "Hello mqtt" is published to this topic.
The documentation for the MQTT.js library can be found within its GitHub repository at https://github.com/mqttjs/MQTT.js. Here, you'll find details about the library's API, examples of how to use it, and other information, such as its upgrade notes, command line tools, and browser support.