Bird
Raised Fist0
NestJSframework~20 mins

NestJS vs Express vs Fastify comparison - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
NestJS vs Express vs Fastify Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Which framework uses a modular architecture with decorators?
Among NestJS, Express, and Fastify, which framework is designed around a modular architecture using decorators to organize code?
AExpress
BNestJS
CFastify
DAll three use decorators by default
Attempts:
2 left
💡 Hint
Think about which framework uses TypeScript features heavily.
❓ component_behavior
intermediate
1:30remaining
What is the default HTTP server used by NestJS?
By default, which HTTP server does NestJS use under the hood?
AFastify
BKoa
CExpress
DHapi
Attempts:
2 left
💡 Hint
NestJS can switch servers but has a default choice.
📝 Syntax
advanced
2:00remaining
Which code snippet correctly creates a Fastify instance in NestJS?
Select the correct way to create a Fastify-based NestJS application.
NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, new FastifyAdapter());
  await app.listen(3000);
}
bootstrap();
ANestFactory.create(AppModule, new KoaAdapter())
BNestFactory.create(AppModule, new ExpressAdapter())
CNestFactory.create(AppModule)
DNestFactory.create(AppModule, new FastifyAdapter())
Attempts:
2 left
💡 Hint
Fastify requires a specific adapter in NestJS.
❓ state_output
advanced
1:30remaining
What is the output when sending a GET request to a simple Express route?
Given this Express code, what will the server respond with when a GET request is made to '/'? const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hello from Express'); }); app.listen(3000);
AHello from Express
BCannot GET /
CHello from NestJS
D404 Not Found
Attempts:
2 left
💡 Hint
Look at the response sent inside the route handler.
❓ lifecycle
expert
2:00remaining
Which lifecycle hook runs after all modules are initialized in NestJS?
In NestJS, which lifecycle hook method is called after all modules have been initialized?
AonApplicationBootstrap()
BonModuleInit()
CafterInit()
DbeforeApplicationShutdown()
Attempts:
2 left
💡 Hint
This hook runs once the whole app is ready, not just a single module.

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

  1. Step 1: Understand framework features

    NestJS is designed with a modular architecture, using decorators and dependency injection to organize code clearly.
  2. 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.
  3. Final Answer:

    NestJS -> Option C
  4. 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

  1. Step 1: Recall Fastify server creation syntax

    Fastify servers are created by calling the fastify() function, not using new keyword.
  2. Step 2: Eliminate other options

    Express uses express(), NestJS uses NestFactory.create(), and Koa uses new Koa().
  3. Final Answer:

    const app = fastify(); -> Option A
  4. 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?
const app = await NestFactory.create(AppModule, { logger: true });
await app.listen(3000);
medium
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

  1. Step 1: Understand NestJS adapters

    NestJS can use Express or Fastify under the hood. Fastify is designed for speed and efficiency.
  2. Step 2: Compare performance traits

    Fastify has optimized HTTP handling and lower overhead, making it faster than Express in most cases.
  3. Final Answer:

    NestJS with Fastify is faster due to optimized HTTP handling -> Option B
  4. 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

  1. Step 1: Check how NestJS app is created with Fastify

    To use Fastify, you must pass the Fastify adapter to NestFactory.create().
  2. 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.
  3. Final Answer:

    You did not use NestFactory.create with Fastify adapter -> Option D
  4. 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

  1. Step 1: Identify requirements

    High performance, automatic validation, and modular structure require a framework with features and speed.
  2. 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.
  3. Final Answer:

    NestJS using Fastify adapter with class-validator and modules -> Option A
  4. Quick Check:

    Structure + validation + speed = NestJS + Fastify [OK]
Hint: Combine NestJS structure + Fastify speed + validation [OK]
Common Mistakes:
  • Choosing Express for automatic validation
  • Ignoring modularity in Fastify alone
  • Using NestJS with Express loses speed advantage
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard