mqtt.js is a client library for the MQTT protocol, written in JavaScript for Node.js and the browser.
MQTT.js solves the problem of connecting JavaScript applications to MQTT brokers for publish-subscribe messaging. It implements the MQTT protocol specification, allowing applications to send and receive messages over MQTT networks. The library handles connection management, message serialization and deserialization, quality of service levels, and automatic reconnection with subscription restoration.
Developers should choose mqtt.js when building real-time messaging features in Node.js applications or browser-based clients that need to communicate with MQTT brokers. It suits projects requiring lightweight, event-driven message passing such as IoT applications, live data feeds, or chat systems. The library supports multiple import styles and includes command-line tools for testing. It works in React Native environments and provides TypeScript support for type-safe development.
The project has undergone significant modernization, with a complete rewrite in TypeScript and removal of support for end-of-life Node versions, now targeting current long-term support releases. The codebase maintains comprehensive test coverage and includes built-in error handling that prevents unhandled errors from breaking client connections. The library supports both MQTT v3.1.1 and experimental MQTT v5 protocol versions, giving applications flexibility in broker compatibility.