# Installation

Use npm command in order to install the mqtt-server module:

```bash
npm install [--save] mqtt-server
```

# Manage your own mqtt broker

The mqtt-server class allows the developer to manager his own mqtt broker in his NodeJS projects:

  - constructor(settings)   : default constructor. If settings is not a bh-section, settings are read from the default configuration file (conf/mqtt-server.conf.json)

  Settings or configuration file format:

  ```json
  {
    "port" : 4242,
    "mongoUrl" : "mongodb://localhost:27017",
    "mongoCollection" : "tests"
  }
  ```

  - init()                  : init the mqtt-server. Return a promise.
  - publish(topic, payload) : publish a new message in the server mqtt network. Return a promise.

# Usage example

```js
var MqttServerClass = require('mqtt-server');

var server = new MqttServerClass(); // Settings read from configuration file

server.init()
  .then(function() {
    server.publish('test', 'test')
      .then(function() {
        console.log('success');
      })
      .catch(function(error) {
        console.error(error);
      });
  })
  .catch(function(error) {
    console.error(error);
  });
```
