What is NestJS and how does it differ from Express?
NestJS is a framework built on top of Express (or Fastify) that adds structure and features like dependency injection, modular architecture, and decorators. Express is a minimal and flexible Node.js web framework without built-in structure.
Click to reveal answer
beginner
What is Fastify known for compared to Express?
Fastify is known for being a fast and low-overhead web framework for Node.js. It focuses on speed and efficient JSON handling, making it faster than Express in many cases.
Click to reveal answer
intermediate
How does NestJS support Fastify?
NestJS can use Fastify as an underlying HTTP server instead of Express. This allows developers to benefit from Fastify's speed while keeping NestJS's structured features.
Click to reveal answer
beginner
Which framework is best for beginners who want minimal setup?
Express is best for beginners who want a simple and minimal setup to quickly build web servers without extra structure.
Click to reveal answer
intermediate
What are the main benefits of using NestJS over Express or Fastify alone?
NestJS provides a clear structure, built-in support for TypeScript, dependency injection, and modular design. This helps build scalable and maintainable applications compared to using Express or Fastify alone.
Click to reveal answer
Which framework is primarily focused on speed and low overhead?
AExpress
BNestJS
CFastify
DKoa
✗ Incorrect
Fastify is designed for speed and low overhead compared to Express and NestJS.
Which framework adds structure and features like dependency injection on top of Express?
AFastify
BNestJS
CHapi
DKoa
✗ Incorrect
NestJS builds on Express or Fastify and adds structure, dependency injection, and modularity.
If you want a minimal and flexible Node.js web framework, which should you choose?
AExpress
BFastify
CMeteor
DNestJS
✗ Incorrect
Express is minimal and flexible, making it a popular choice for simple setups.
Can NestJS use Fastify as its HTTP server?
AFastify is a competitor, not compatible
BNo, only Express is supported
COnly with third-party plugins
DYes, NestJS supports Fastify
✗ Incorrect
NestJS supports Fastify as an alternative to Express for its HTTP server.
Which framework is best suited for building large, maintainable applications with TypeScript?
ANestJS
BFastify
CExpress
DSocket.io
✗ Incorrect
NestJS is designed for scalable, maintainable apps with TypeScript support and modular architecture.
Explain the main differences between NestJS, Express, and Fastify.
Think about simplicity, speed, and structure.
You got /4 concepts.
When would you choose NestJS over Express or Fastify?
Consider project size and complexity.
You got /4 concepts.
Practice
(1/5)
1. Which framework is known for providing a structured architecture with decorators and dependency injection?
easy
A. Fastify
B. Express
C. NestJS
D. Koa
Solution
Step 1: Understand framework features
NestJS is designed with a modular architecture, using decorators and dependency injection to organize code clearly.
Step 2: Compare with other frameworks
Express is minimal and flexible but lacks built-in structure; Fastify focuses on speed but not on architectural patterns.
Final Answer:
NestJS -> Option C
Quick Check:
Structured framework = NestJS [OK]
Hint: Structured + decorators = NestJS [OK]
Common Mistakes:
Confusing Express's flexibility with structure
Thinking Fastify has built-in dependency injection
Choosing Koa which is unrelated here
2. Which of the following is the correct way to create a Fastify server instance?
easy
A. const app = fastify();
B. const app = express();
C. const app = new NestFactory();
D. const app = new Koa();
Solution
Step 1: Recall Fastify server creation syntax
Fastify servers are created by calling the fastify() function, not using new keyword.
Step 2: Eliminate other options
Express uses express(), NestJS uses NestFactory.create(), and Koa uses new Koa().
Final Answer:
const app = fastify(); -> Option A
Quick Check:
Fastify instance = fastify() [OK]
Hint: Fastify uses fastify() function call [OK]
Common Mistakes:
Using new keyword with fastify
Confusing Express and Fastify syntax
Using NestFactory directly for Fastify
3. Given the following code snippet, what will be the main difference in performance between NestJS using Express and Fastify?
A. NestJS with Express is faster due to simpler middleware
B. NestJS with Fastify is faster due to optimized HTTP handling
C. Both have identical performance because NestJS abstracts the server
D. NestJS with Express supports HTTP/2 by default, Fastify does not
Solution
Step 1: Understand NestJS adapters
NestJS can use Express or Fastify under the hood. Fastify is designed for speed and efficiency.
Step 2: Compare performance traits
Fastify has optimized HTTP handling and lower overhead, making it faster than Express in most cases.
Final Answer:
NestJS with Fastify is faster due to optimized HTTP handling -> Option B
Quick Check:
Fastify = faster HTTP handling [OK]
Hint: Fastify is faster than Express in NestJS [OK]
Common Mistakes:
Assuming Express is faster due to simplicity
Thinking NestJS removes all performance differences
Confusing HTTP/2 support defaults
4. You wrote a NestJS app using Fastify adapter but get an error: TypeError: app.listen is not a function. What is the most likely cause?
medium
A. You forgot to import FastifyModule in AppModule
B. Fastify does not support listen method
C. You called app.listen before await
D. You did not use NestFactory.create with Fastify adapter
Solution
Step 1: Check how NestJS app is created with Fastify
To use Fastify, you must pass the Fastify adapter to NestFactory.create().
Step 2: Understand error cause
If you skip the adapter, NestJS defaults to Express, but if you mix Fastify code without adapter, app.listen may be undefined.
Final Answer:
You did not use NestFactory.create with Fastify adapter -> Option D
Quick Check:
Fastify adapter required for app.listen [OK]
Hint: Use Fastify adapter in NestFactory.create [OK]
Common Mistakes:
Assuming FastifyModule import is enough
Calling listen without await causes different error
Thinking Fastify lacks listen method
5. You want to build a high-performance REST API with automatic validation, modular structure, and fast response times. Which combination best fits this requirement?
hard
A. NestJS using Fastify adapter with class-validator and modules
B. Fastify with no framework on top
C. NestJS using Express adapter without validation
D. Express with manual middleware and no structure
Solution
Step 1: Identify requirements
High performance, automatic validation, and modular structure require a framework with features and speed.
Step 2: Match frameworks to needs
Express alone lacks structure and automatic validation; Fastify alone lacks modularity; NestJS provides structure and validation, and Fastify adapter adds speed.
Final Answer:
NestJS using Fastify adapter with class-validator and modules -> Option A