Skip to content

Instantly share code, notes, and snippets.

@cbh6
Created April 27, 2018 10:54
Show Gist options
  • Save cbh6/707bc906ed22c060a4f3c1bc2b8aa506 to your computer and use it in GitHub Desktop.
Save cbh6/707bc906ed22c060a4f3c1bc2b8aa506 to your computer and use it in GitHub Desktop.
var express = require("express");
var bodyParser = require("body-parser");
var app = express();
var mqttHandler = require('./mqtt_handler');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
var mqttClient = new mqttHandler();
mqttClient.connect();
// Routes
app.post("/send-mqtt", function(req, res) {
mqttClient.sendMessage(req.body.message);
res.status(200).send("Message sent to mqtt");
});
var server = app.listen(3000, function () {
console.log("app running on port.", server.address().port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment