title: node.js mqtt client using TLS
body: <p>I am trying to implement a node.js mqtt client with TLS using the package below;</p>
  
  <p><a href="https://www.npmjs.com/package/mqtt#client" rel="noreferrer">https://www.npmjs.com/package/mqtt#client</a></p>
  
  <p>The code for running mqtt client without TLS is as follows;</p>
  
  <pre><code>var mqtt = require('mqtt')
  var client  = mqtt.connect('mqtt://test.mosquitto.org')
  
  client.on('connect', function () {
    client.subscribe('presence')
    client.publish('presence', 'Hello mqtt')
  })
  
  client.on('message', function (topic, message) {
    // message is Buffer 
    console.log(message.toString())
    client.end()
  })
  </code></pre>
  
  <p>How should the above code be modified to use TLS on the mqtt client?</p>
  
  <p>The mosca MQTT broker was run as a stand-alone using the command below;</p>
  
  <pre><code>mosca --key ./tls-key.pem --cert ./tls-cert.pem --http-port 3000 --http-bundle --http-static ./ | pino
  </code></pre>