- Author: Satish Wadekar
- License: MIT
- Repo URL: https://github.com/Satish-A-Wadekar/mqtt-with-mosquitto-broker-node
- Contacts: satish.a.wadekar@gmail.com
- Requirements: Mosquitto server, Node.js v6 or higher, npm OR yarn
This is a very quick & simple boilerplate where you can develop Node.js app with MQTT protocols for Pub/Sub message exchange module with the help of Mosquitto broker (custom configuration)
You need to install Mosquitto broker server on your machine to run this project locally, to install Mosquitto you can check this link https://mosquitto.org/download/.
Mosquitto can be installed from the homebrew project
brew install mosquitto
Install all dependencies
yarn install OR npm install
To run this project, you will need to add the following environment variables to your .env file. I have already added env-template file in repo which you can use for your .env file setup
HOST
PORT
USERNAME
PASSWORD
TOPIC
on first terminal window run index.js to start the mosquitto server
node index.js
if you face any error while server starting, just kill all previously running mosquitto servers at your local. to do this just run following command
killall mosquitto
on second terminal window run subscriber code
node src/mqttSub.js
on third terminal window run publisher code
node src/mqttPub.js
For support, email satish.a.wadekar@gmail.com.