What is @nestjs/microservices?
@nestjs/microservices is a package for building microservice-based applications using the NestJS framework. It provides a set of tools and abstractions to create and manage microservices, allowing for communication between different parts of an application through various transport layers such as TCP, Redis, NATS, MQTT, and more.
What are @nestjs/microservices's main functionalities?
TCP Transport
This feature allows you to create a microservice that communicates over TCP. The code sample demonstrates how to set up a TCP microservice using NestFactory.
const app = await NestFactory.createMicroservice(AppModule, { transport: Transport.TCP, options: { host: '127.0.0.1', port: 8877 } }); app.listen(() => console.log('Microservice is listening'));
Redis Transport
This feature allows you to create a microservice that communicates over Redis. The code sample shows how to set up a Redis microservice using NestFactory.
const app = await NestFactory.createMicroservice(AppModule, { transport: Transport.REDIS, options: { url: 'redis://localhost:6379' } }); app.listen(() => console.log('Microservice is listening'));
NATS Transport
This feature allows you to create a microservice that communicates over NATS. The code sample demonstrates how to set up a NATS microservice using NestFactory.
const app = await NestFactory.createMicroservice(AppModule, { transport: Transport.NATS, options: { url: 'nats://localhost:4222' } }); app.listen(() => console.log('Microservice is listening'));
MQTT Transport
This feature allows you to create a microservice that communicates over MQTT. The code sample shows how to set up an MQTT microservice using NestFactory.
const app = await NestFactory.createMicroservice(AppModule, { transport: Transport.MQTT, options: { url: 'mqtt://localhost:1883' } }); app.listen(() => console.log('Microservice is listening'));
gRPC Transport
This feature allows you to create a microservice that communicates over gRPC. The code sample demonstrates how to set up a gRPC microservice using NestFactory.
const app = await NestFactory.createMicroservice(AppModule, { transport: Transport.GRPC, options: { package: 'hero', protoPath: join(__dirname, './hero.proto') } }); app.listen(() => console.log('Microservice is listening'));
Other packages similar to @nestjs/microservices
micro
Micro is a framework for creating microservices in Node.js. It focuses on simplicity and minimalism, providing a lightweight solution for building microservices. Compared to @nestjs/microservices, Micro is less opinionated and does not provide as many built-in transport layers or integrations.
seneca
Seneca is a microservices toolkit for Node.js. It provides a way to organize business logic into microservices and supports various transport mechanisms. Seneca is more flexible in terms of plugin architecture but may require more configuration compared to @nestjs/microservices.
moleculer
Moleculer is a fast and powerful microservices framework for Node.js. It offers a wide range of features, including service discovery, load balancing, and fault tolerance. Moleculer provides more built-in features for microservice orchestration compared to @nestjs/microservices.
A progressive Node.js framework for building efficient and scalable server-side applications.
Description
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Nest makes use of Express, but also, provides compatibility with a wide range of other libraries, like e.g. Fastify, allowing for easy use of the myriad third-party plugins which are available.
Philosophy
In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like Angular, React and Vue which improve developer productivity and enable the construction of fast, testable, extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers and tools for Node, none of them effectively solve the main problem - the architecture.
Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.
Getting started
Questions
For questions and support please use the official Discord channel. The issue list of this repo is exclusively for bug reports and feature requests.
Issues
Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.
Consulting
With official support, you can get expert help straight from Nest core team. We provide dedicated technical support, migration strategies, advice on best practices (and design decisions), PR reviews, and team augmentation. Read more about support here.
Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please read more here.
Backers
Stay in touch
License
Nest is MIT licensed.