This is a MQTT broker demo using aedes module. This sample is ready to deploy to Heroku. This code will run HTTP server with MQTT-over-websocket capabilities. So, you need to replace mqtt://
protocol with ws://
one.
To test if it works, try this code below.
const mqtt = require("mqtt");
const client = mqtt.connect('ws://YOUR-APP-INSERT-HERE.herokuapp.com');
client.on("connect", () => {
client.subscribe("presence", (err) => {
if (!err) {
client.publish("presence", "Hello mqtt");
}
});
});
client.on("message", (topic, message) => {
// message is Buffer
console.log(message.toString());
client.end();
});