0
0
NestJSframework~10 mins

NestJS vs Express vs Fastify comparison - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - NestJS vs Express vs Fastify comparison
Start Request
NestJS Middleware
NestJS Controller
Underlying HTTP Framework
Express
Handle Request & Response
Send Response
End
Shows how NestJS handles requests by using middleware and controllers, then delegates to an underlying HTTP framework like Express or Fastify to process and respond.
Execution Sample
NestJS
import { Controller, Get } from '@nestjs/common';
@Controller('hello')
export class HelloController {
  @Get()
  getHello() { return 'Hello World'; }
}
A simple NestJS controller that responds with 'Hello World' when a GET request is made to /hello.
Execution Table
StepActionNestJS LayerUnderlying FrameworkResult
1Receive HTTP GET /helloMiddleware processes requestExpress or Fastify receives requestRequest passed to controller
2Controller method getHello() calledController handles routeUnderlying framework idleReturns 'Hello World' string
3NestJS sends responseResponse preparedUnderlying framework sends HTTP responseClient receives 'Hello World'
4Request cycle endsCleanup if neededRequest closedReady for next request
💡 Request handled fully by NestJS and underlying framework sends response back to client
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
requestundefinedHTTP GET /hello objectPassed to controllerResponse preparedRequest closed
responseundefinedundefinedundefined'Hello World' stringSent to client
Key Moments - 2 Insights
Why does NestJS use Express or Fastify under the hood?
NestJS is a framework that builds on top of existing HTTP servers like Express or Fastify to add structure and features. The execution_table shows NestJS middleware and controllers handle logic, but the underlying framework manages the actual HTTP request and response.
How does Fastify differ from Express in this setup?
Fastify is designed for speed and low overhead, so when NestJS uses Fastify (seen in the underlying framework column), requests may be processed faster compared to Express. The flow is similar but performance differs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at Step 2?
ANestJS controller method is called to handle the route
BUnderlying framework sends the HTTP response
CRequest is received by the server
DRequest cycle ends and cleanup happens
💡 Hint
Check the 'Action' and 'NestJS Layer' columns at Step 2 in the execution_table
At which step does the client receive the 'Hello World' response?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for when the response is sent to the client in the 'Result' column
If NestJS used only Express, which column in the execution_table would change?
ANestJS Layer
BUnderlying Framework
CAction
DResult
💡 Hint
The 'Underlying Framework' column shows which HTTP server is used
Concept Snapshot
NestJS is a framework that uses Express or Fastify underneath.
It adds structure with controllers and middleware.
Express is popular and easy; Fastify is faster and lighter.
NestJS handles routing and logic; Express/Fastify handle HTTP.
Choose Fastify for speed, Express for ecosystem.
NestJS lets you switch easily between them.
Full Transcript
This visual execution compares NestJS with Express and Fastify. NestJS acts as a structured layer on top of HTTP servers like Express or Fastify. When a request comes in, NestJS middleware processes it, then the controller handles the route logic. The underlying framework (Express or Fastify) manages the actual HTTP request and response. Express is widely used and easy to work with, while Fastify offers better performance. The execution table shows the step-by-step flow: receiving the request, calling the controller, preparing the response, and sending it back to the client. Variables like request and response change state through these steps. Key points include understanding NestJS's role as a wrapper and the performance differences between Express and Fastify. The quiz tests understanding of these steps and roles. Overall, NestJS provides a clean structure while leveraging powerful HTTP frameworks underneath.