NodeJS MQTT minimal subscribe example
Also see:NodeJS MQTT minimal subscribe example with JSON messages
example.js
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://user:[email protected]')
client.on('connect', () => {
client.subscribe('mytopic');
})
client.on('message', (topic, message) => {
console.log(topic, message)
})
If required, you can install the mqtt
library using
example.sh
npm i --save mqtt
Check out similar posts by category:
Javascript, MQTT, NodeJS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow