NestJS Platforms: Express vs. Fastify
Explore the differences between Express and Fastify as underlying HTTP platforms for NestJS applications. Understand their strengths, performance characteristics, middleware ecosystems, and scenarios where each platform is best suited, helping you choose the right framework for your RESTful API development.
NestJS platforms
NestJS uses Express as the underlying platform by default but can also work with other NodeJS HTTP frameworks. This is because NestJS implements a framework adapter that abstracts away the platform-specific details in middleware and request handling.
The out-of-the-box alternative framework is Fastify. Fastify is known for its exceptional speed and low overhead, making it a great choice for high-performance applications. On the other hand, Express has a robust ecosystem and is widely adopted, making it suitable for a wide range of use cases.
Use Fastify in NestJS
To use Fastify, we need to install the following package:
npm i --save @nestjs/platform-fastify
Then, we can modify the main.ts file to use the Fastify adapter.
In the bootstrap() function above, we use NestFactory.create to create a NestJS application instance. It takes the following two arguments:
AppModule: This is the root module of our NestJS ...