
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
A MQTT module for Nest.js. Compatible with emqtt.
$ npm install nest-mqtt --save
Nest-mqtt will register as a global module.
You can import with configuration
// app.module.ts
import { Module } from '@nestjs/common';
import { MqttModule } from 'nest-mqtt';
@Module({
imports: [MqttModule.forRoot(options)]
})
export class AppModule {}
or use async import method
// app.module.ts
import { Module } from '@nestjs/common';
import { MqttModule } from 'nest-mqtt';
@Module({
imports: [MqttModule.forRootAsync({
useFactory: () => options,
})]
})
export class AppModule {}
You can define any subscriber or consumer in any provider. For example,
import { Injectable } from '@nestjs/common';
import { Subscribe, Payload, Topic } from 'nest-mqtt';
@Injectable()
export class TestService {
@Subscribe('test')
test() {
}
@Subscribe({
topic: 'test2',
transform: payload => payload.toString(),
})
test2() {
}
}
Also, you can inject parameter with decorator:
import { Injectable } from '@nestjs/common';
import { Subscribe, Payload } from 'nest-mqtt';
@Injectable()
export class TestService {
@Subscribe('test')
test(@Payload() payload) {
console.log(payload);
}
}
Here are all supported parameter decorators:
Get the payload data of incoming message. You can pass in a transform function for converting.
Get the topic of incoming message.
Get the raw packet of incoming message.
Get the wildcard part of topic. It will return an array of string which extract from topic. For example:
When subscribe the topic "test/+/test/+" and incoming topic is "test/1/test/2", you will get the array ["1", "2"]
.
Nest-mqtt wrap some functions with Promise
and provide a provider.
import { Inject, Injectable } from '@nestjs/common';
import { MqttService } from 'nest-mqtt';
@Injectable()
export class TestService {
constructor(
@Inject(MqttService) private readonly mqttService: MqttService,
) {}
async testPublish() {
this.mqttService.publish('topic', {
foo: 'bar'
});
}
}
nest-mqtt support emq shared subscription
Module options support queue and share property for globally converting all topic to shared topic except configured in subscription options.
// app.module.ts
import { Module } from '@nestjs/common';
import { MqttModule } from 'nest-mqtt';
@Module({
imports: [MqttModule.forRoot({
host: '127.0.0.1',
queue: true,
share: 'group1'
})]
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import { Subscribe, Payload, Topic } from 'nest-mqtt';
@Injectable()
export class TestService {
@Subscribe('test')
test() {
}
@Subscribe({
topic: 'test2',
queue: true,
})
test2() {
}
}
The priority of subscribe is higher than the global mode. If you want to specify a topic do not use the shared mode, set it as false in subscribe decorator.
Nest-mqtt is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
nest-mqtt is MIT licensed.
FAQs
A MQTT module for Nest.js
The npm package nest-mqtt receives a total of 191 weekly downloads. As such, nest-mqtt popularity was classified as not popular.
We found that nest-mqtt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.