@sansitech/express-mqtt

1.0.2 • Public • Published

Express Mqtt

const mqtt = require('mqtt');
const expressMqtt = require('@sansitech/express-mqtt');

const client  = mqtt.connect('mqtt://test.mosquitto.org')
 
client.on('connect', function () {
  client.subscribe('test/hello', function (err) {
    if (!err) {
      client.publish('test/hello', 'Hello mqtt')
    }
  })
});


const app = expressMqtt(client);
// use it as express, support 
app.get('test/hello',(req,next)=>{
  console.log(`url:${req.url}`);
  req.ok = 'ok';
  next();
},(req)=>{
  console.log(`ok: ${req.ok}`)
});

Readme

Keywords

none

Package Sidebar

Install

npm i @sansitech/express-mqtt

Weekly Downloads

25

Version

1.0.2

License

ISC

Unpacked Size

23.2 kB

Total Files

10

Last publish

Collaborators

  • hanyuzhou2006
  • ccw